0% found this document useful (0 votes)
2 views8 pages

Practical Program File

The document contains a series of practical programming exercises in C, including programs for adding integers, swapping variables, calculating sums and averages, and converting units. It also includes programs for geometric calculations like area and volume of shapes, temperature conversion, and displaying student information. Each program is accompanied by example outputs demonstrating successful execution.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Practical Program File

The document contains a series of practical programming exercises in C, including programs for adding integers, swapping variables, calculating sums and averages, and converting units. It also includes programs for geometric calculations like area and volume of shapes, temperature conversion, and displaying student information. Each program is accompanied by example outputs demonstrating successful execution.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical No 2

[Link] a program to add two integer number


#include <stdio.h>
int main() {
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculate the sum
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}

OUTPUT*******************************************

Enter two integers: 10


20
10 + 20 = 30

=== Code Execution Successful ===

[Link] a program to interchange contents of two


variables(a & b) .input values for these variables through
keyboard.
#include<stdio.h>
int main() {
int first, second, temp;
printf("Enter first number: ");
scanf("%d", &first);
printf("Enter second number: ");
scanf("%d", &second);
// value of first is assigned to temp
temp = first;
// value of second is assigned to first
first = second;
// value of temp (initial value of first) is assigned to second
second = temp;
printf("\nAfter swapping, first number = %.d\n", first);
printf("After swapping, second number = %.d", second);
return 0;
}

OUTPUT*******************************************

Enter first number: 10


Enter second number: 20

After swapping, first number = 20


After swapping, second number = 10

=== Code Execution Successful ===

[Link] a program to calculate sum of a five digit number


use modulus operator
#include<stdio.h>
int main()
{
int n,sum=0,m;
printf("Enter a number:");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
printf("Sum is=%d",sum);
return 0;
}

OUTPUT*******************************************

Enter a number:154
Sum is=10

=== Code Execution Successful ===


[Link] a program to find average of five integer numbers
#include <stdio.h>
int main()
{
int num; // Declare 'num' to read number from users
int sum, i; // Declare variables 'sum' to keep sum of numbers & 'i' used in for loop
float average; // Declae variable 'average' of float type to save average value
printf("Enter five numbers: "); // Display message to enter numbers
for(i=0; i<5; i++){ // Loop for 5 times
scanf("%d", &num); // Read number
sum = sum + num; // Add into 'sum'
}
average = sum/5; // Calculate average by dividing 'sum' by 5
printf("Average = %f", average); // Display average
return 0;
}

OUTPUT*******************************************
Enter five numbers: 1
2
3
4
5
Average = 3.000000

=== Code Execution Successful ===


Practical No 3
[Link] a program to find area and perimeter of a circle.
#include <stdio.h>
#define PI 3.14f
int main()
{
float rad,area, perm;
printf("Enter radius of circle: ");
scanf("%f",&rad);
area=PI*rad*rad;
perm=2*PI*rad;
printf("Area of circle: %f \nPerimeter of circle: %f\n",area,perm);
return 0;
}
OUTPUT*******************************************

Enter radius of circle: 2.34


Area of circle: 17.193384
Perimeter of circle: 14.695200
=== Code Execution Successful ===

[Link] a program for convert temperature from Fahrenheit to


Centigrade. (Formula: Temperature in degrees Celsius (°C) =
(Temperature in degrees Fahrenheit (°F) - 32) * 5/9)
#include<stdio.h>
int main(){
float fahrenheit, celsius;
//get the limit of fibonacci series
printf("Enter Fahrenheit: ");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f ", celsius);
return 0;
}
OUTPUT*******************************************
Enter Fahrenheit: 100
Celsius: 37.777779
=== Code Execution Successful ===
[Link] a program to find surface area and volume of a
sphere.
#include <stdio.h>
#include <math.h>
int main()
{
float radius = 0;
float volume = 0;
float area = 0;
printf("Enter the radius: ");
scanf("%f", &radius);
volume = (4.0 / 3) * (3.14) * pow(radius, 3);
area = 4 * (3.14) * pow(radius, 2);
printf("Volume of Sphere : %f\n", volume);
printf("Surface area of Sphere: %f\n", area);
return 0;
}

OUTPUT*******************************************

Enter the radius: 2.45


Volume of Sphere : 61.569649
Surface area of Sphere: 75.391403

[Link] a C program to convert kilometer into meters and


feet.
#include<stdio.h>
int main()
{
float km, m,f;
printf("Enter distance in kilometer: ");
scanf("%f", &km);
m = km * 1000;
f= km * 3280.84;
printf("%0.3f Kilometer = %0.3f Meter", km, m);
printf("\n %0.3f Kilometer = %0.3f Feet", km, f);
return 0;
}
OUTPUT*******************************************
Enter distance in kilometer: 2
2.000 Kilometer = 2000.000 Meter
2.000 Kilometer = 6561.680 Feet

Practical No 5
Write a program to display following information of a student Name,
Roll Number, Percentage (upto 2 decimal places), Date of Birth, Branch,
and College as follows.
Name: Yashwant Patil
Rollno:15
Marks: 65.20
Date of Birth: 21/02/2001
Branch:Comp

#include <stdio.h>
int main() {
char name[50], dob[15], branch[10];
int rollno;
float marks;
printf("Enter Name: ");
scanf("%s", name);
printf("Enter Roll Number: ");
scanf("%d", &rollno);
printf("Enter Marks: ");
scanf("%f", &marks);
printf("Enter Date of Birth (DD/MM/YYYY): ");
scanf("%s", dob);
printf("Enter Branch: ");
scanf("%s", branch);
printf("\nName: %s\n", name);
printf("Rollno: %d\n", rollno);
printf("Marks: %.2f\n", marks);
printf("Date of Birth: %s\n", dob);
printf("Branch: %s\n", branch);
return 0;
}
OUTPUT*******************************************
Enter Name: yashwanti
Enter Roll Number: 15
Enter Marks: 65.20
Enter Date of Birth (DD/MM/YYYY): 21/02/2001
Enter Branch: comp

Name: yashwanti
Rollno: 15
Marks: 65.20
Date of Birth: 21/02/2001
Branch: comp

Practical No 6

1. Ask for 2 numbers and tell whether both are same or not.
#include <stdio.h>

int main() {
int num1, num2;
// Asking for two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Using the conditional operator to check if both numbers are same or not
(num1 == num2) ? printf("Both numbers are same.\n") : printf("Both numbers are not
same.\n");
return 0;
}
OUTPUT*******************************************
Enter the first number: 10
Enter the second number: 20
Both numbers are not same.

Enter the first number: 10


Enter the second number: 10
Both numbers are same.
(2) Ask for a number and tell whether it is odd or even.
#include <stdio.h>
int main() {
int num;
// Ask the user to enter a number
printf("Enter a number: ");
scanf("%d", &num);
// Using relational and conditional operators to check if the number is even or odd
(num % 2 == 0) ? printf("%d is Even\n", num) : printf("%d is Odd\n", num);
return 0;
}

OUTPUT*******************************************
Enter a number: 10
10 is Even

Enter a number: 7
7 is Odd
(3) Tell whether entered number is positive or negative.
#include <stdio.h>
int main() {
float number;
// Ask the user to enter a number
printf("Enter a number: ");
scanf("%f", &number);
// Check if the number is positive, negative, or zero
if (number > 0) {
printf("The number %.2f is positive.\n", number);
} else if (number < 0) {
printf("The number %.2f is negative.\n", number);
} else {
printf("The number is zero.\n");
}
return 0;
}
OUTPUT*******************************************
Enter a number: 5
The number 5.00 is positive.
Enter a number: 0
The number is zero.

You might also like