Practical 2 - Introduction To C Programming: 1. Write A C Program To Find The Average of 3 Numbers
Practical 2 - Introduction To C Programming: 1. Write A C Program To Find The Average of 3 Numbers
Practical 2 - Introduction To C Programming: 1. Write A C Program To Find The Average of 3 Numbers
#include<stdio.h>
void main()
float a,b,c,d;
scanf("%f%f%f",&a,&b,&c);
d=(a+b+c)/3;
Output:-
#include<stdio.h>
void main()
float a,b,c,d;
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
printf("The principal value is %f, Rate of interest is %f, and Time in years is %f.\n\n",a,b,c);
d=(a*b*c)/100;
Output:-
100000
20000
The principal value is 100000.000000, Rate of interest is 20000.000000, and Time in years is
5.000000.
#include<stdio.h>
void main()
float a,b,c,d,e;
scanf("%f",&a);
b=a*1000;
c=b*100;
d=a*3281;
e=d*12;
Output:-
#include<stdio.h>
void main()
float a,b;
scanf("%f",&a);
b=a*3600;
Output:-
void main()
float a,area,volume;
scanf("%f",&a);
area=6*(a*a);
volume=a*a*a;
Output:-
Enter side of a cube: 3
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter a value:\n");
scanf("%d",&a);
printf("Value entered is %d.\n\n",a);
b=a*a;
c=a*a*a;
printf("square of %d is %d,",a,b);
printf("and cube of %d is %d,\n\n",a,c);
}
Output:-
Enter a value:
25
void main()
int a,b;
scanf("%d%d",&a,&b);
int c,d,e,f,g;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
Output:-
Enter 2 integer values:
void main()
scanf("%f",&bs);
da=0.40*bs;
hra=0.20*bs;
gs=bs+da+hra;
Output:-
Enter basic salary of Ramesh: 20000
void main()
float eng, mat, sci, alg, geo ,socio, polsci, sum, perc;
scanf("%f",&eng);
scanf("%f",&mat);
scanf("%f",&sci);
scanf("%f",&alg);
scanf("%f",&geo);
scanf("%f",&socio);
scanf("%f",&polsci);
sum=eng+mat+sci+alg+geo+socio+polsci;
perc=(eng+mat+sci+alg+geo+socio+polsci)/700*100;
}
Output:-
Enter marks obtained in English: 80
10. Write a C program to calculate area and perimeter of the rectangle. Program
should accept length and breadth of a rectangle as input.
Input:-
#include<stdio.h>
void main()
float l,b,area,per;
scanf("%f%f",&l,&b);
area=l*b;
per=2*(l+b);
Output:-
Enter length and breadth of rectangle: 5 6
void main()
float radius,area,circum;
scanf("%f",&radius);
area=3.14*(radius*radius);
circum=2*3.14*radius;
Output:-
Enter radius of circle: 10
void main()
int x,a,b,c,sum;
scanf("%d",&x);
a=x/100;
b=(x%100)/10;
c=x%10;
sum=a+b+c;
Output:-
Enter three digit number: 125
#include<stdio.h>
void ()
int x,y,temp;
scanf("%d",&x);
scanf("%d",&y);
temp=y;
y=x;
x=temp;
printf("The value interchanged will turn first value into %d and second value into %d\n\n",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("The value now turns into original value with first value is%d and second value is %d\n\
n",x,y);
Output:-
Enter first value: 40
The value interchanged will turn first value into 32 and second value into 40
The value now turns into original value with first value is40 and second value is 32
14. Write a C program to find and print the total marks obtained and percentage of
5 subjects.
Input:-
#include<stdio.h>
void main()
scanf("%f",&eng);
scanf("%f",&mat);
scanf("%f",&sci);
scanf("%f",&alg);
scanf("%f",&geo);
sum=eng+mat+sci+alg+geo;
perc=(eng+mat+sci+alg+geo)/500*100;
Output:-
Enter marks obtained in English: 50
void main()
int c,f;
scanf("%d",&c);
f=(9*c)/5+32;
c=(5*f)/9-32;
Output:-