1. Write a C program to display “This is my first C Program”.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
printf("This is my first C Program");
Output: This is my first C Program
2. Write a C program to add two numbers (2 and 6) and display its sum.
Source Code:
#include<stdio.h>
#include<conio.h>
int main(){
int a=2,b=6,sum;
sum = a+b ;
printf("sum=%d",sum);
}
Output: sum=8
3. Write a C program to multiply two numbers (4 and 5) and display its product.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
int a=4,b=5,m;
m = a*b;
printf("multiplication= %d",m );
}
Output: multiplication: 20
4. Write a C program to calculate area and circumference of a circle.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
float PI=3.14, rad , a, ci;
printf("Enter radius of circle:");
scanf(" %f", &rad);
a=PI*rad*rad;
ci=2*PI*rad;
printf("area= %.2f \n circumference=%.2f",a,ci );
Sample input: Enter radius of circle: 3
Sample output: area=28.26
circumference=18.84
5. Write a C program to perform addition, subtraction, division and multiplication of two numbers.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
float a,b,sum,sub,mul,div;
printf("Enter two integers:");
scanf(" %f %f",&a,&b);
sum = a+b ;
sub=a-b;
mul=a*b;
divn=a/b;
printf("sum= %f \n sub= %f \n mul= %f \n div=%f ",sum,sub,mul,divn);
}
Sample input: 16, 4
Sample Output:sum= 20
sub=12
mul=64
div=4
6. Write C program to evaluate each of the following equations.
(i)V=u+at (ii)S=ut+1/2at2 (iii)T=2a+ √b+9c (iv)H=√(b2 +p2 )
Source code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
float V,u,acc,t,S,a,b,c,p,H,T;
printf("Enter u,acc,t,a,b,c,p:");
scanf(" %f %f %f %f %f %f %f",&u,&acc,&t,&a,&b,&c,&p);
V=u+acc*t;
S=u*t+1/(2a*t*t);
T=2*a+ sqrt(b)+9*c;
H=sqrt(b*b+p*p);
printf("V=%.2f \n S=%.2f \n T=%.2f \n H=%.2f \n ",V,S,T,H);
Sample input: Enter u,acc,t,a,b,c,p: 2 2 5 3 9 6 4
Sample output: V=12.00
S=10.01
T=63.00
H=9.85
Exercise-1
1. Write a program to take input of name, class_id, and marks obtained by a student in 5 subjects
of 100 marks each and display the name, class_id with percentage score.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
char name[100], id[50];
float a, b,c,d,e, perc_scr;
printf("Enter name:");
scanf("%s" , name);
printf("\n Enter class_id:");
scanf("%s" ,id );
printf("\n Enter marks of 5 subjects(out of 100):");
scanf("%f %f %f %f %f",&a, &b, &c, &d, &e );
perc_scr=(a+b+c+d+e)/5;
printf("Name=%s \n Class_ID=%s \n Percent score=%.2f" , name, id, perc_scr);
}
Sample input: Enter name: Adiba
Enter class_id:2154901054
Enter marks of 5 subjects(out of 100): 70 80 90 76 78
Sample output: Name: Adiba
Class_ID: 2154901054
Percent score: 78.80
2. Write a program to take randomly 10 numbers then find their average.
Source code:
#include<stdio.h>
#include<conio.h>
int main(){
int a,b,c,d,e,f,g,h,i,j,avg;
printf("Enter 10 random numbers:");
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
avg=(a+b+c+d+e+f+g+h+i+j)/10;
printf("average=%d",avg);
Sample input: Enter 10 random numbers: 1 2 3 4 5 6 7 8 9 10
Sample output: average=5