To understand the below program first you have to learn how to write a program . You have to study the structure of c programs . Then you have to study the input-output system .
Now you are ready to study the following program.
P1. Program to find the sum of two numbers.
#include<stdio.h>#include<conio.h>
void main()
{
clrscr();
int a,b,sum;
printf("enter two numbers");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum=%d",sum);
getch();
}
C program to add two numbers |
P2. Program to input three numbers after that find sum and average.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,sum,avg;
printf("enter three no.");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
avg=sum/3;
printf("sum=%d\n avg=%d",sum,avg);
getch();
}
P3. Program to input amount,rate and time after that find simple interest.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int amount,rate,time,sinterest;
printf("enter the amount, rate and time");
scanf("%d%d%d",&a,&b,&c);
sinterest=a*b*c/100;
printf("SI=%d",sinterest);
getch();
}
P4. Program to input side, after that find area and perimeter of square.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int s,area,peri;
printf("enter the side of square");
scanf("%d",&s);
area= s*s;
peri= 4*s;
printf("\nArea=%d\n Perimeter= %d",area,peri);
getch();
}
P5. Program to input amount of product after that calculate net amount ,if discount is 20%.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int pamt,dis,namt;
printf("enter the purchase amount");
scanf("%d",&pamt);
dis=pamt*20/100;
namt=pamt-dis;
printf("Purchase amount=%d\n Discount=%d\n Net payable amount= %d",pamt,dis,namt);
getch();
}
6. Program to input a numbers and calculate the square root.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, sq;
printf( “ enter a number “ );
scanf( “ %d “, &a );
sq = a*a;
printf( “ square root = %d “, sq);
getch();
}
7. Program to input marks of five subject after that find total marks and percentage marks .
#incude<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, c , d, e, T, P;
printf(“ enter the marks of five subject “);
scanf( “ %d %d %d %d %d “, &a, &b, &c, &d,
&e );
T= a+ b+ c+ d+ e;
P= T/5;
printf( “ Total marks = %d \n percentage= %d”, T, P);
getch();
}
8.Program to input radius and after that find area and circumference of circle.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float r, A, C;
printf(“enter the radius of the circle “);
scanf( “ %f”, &r);
A= 3.14 * r * r;
C= 2 * 3.14 * r;
printf(“ Area = %f \n Circumference= %d”);
getch();
}
9. Program to input two numbers after that swap /interchange it.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b, c;
printf(“ enter the two numbers “);
scanf(“ %d %d”, &a, &b);
c=a;
a=b;
b=c;
printf(“ %d %d”, a,b);
getch();
10. Program to swap two numbers without extra variable.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
printf(“enter the two numbers “);
scanf(“%d %d”, &a, &b);
a= a+b;
b=a-b;
a=a-b;
printf( “ %d %d”,
a,b);
getch();
}
11. Program to input any four digit number after that find sum of all digits of the number.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a, sum, r1, r2, r3, r4, q1, q2, q3;
printf(“enter a of four digits number “);
scanf(“ %d “, &a);
r1= a%10;
q1= a/10;
r2= q1%10;
q2= q1/10;
r3= q2%10;
q3= q2/10;
r4= q3%10;
s= r1+ r2+ r3+ r4;
printf(“ sum of its digits = %d”, s);
getch();
}
12. Program to input time in second after that convert it into hour, minute and remaining second for given format.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int s, m , h;
printf(“ enter the time inn sec “);
scanf(“ %d ”,
&s);
h= s/3600;
s= s %3600;
m= s/60;
s= s%60;
printf(“ hour= %d\n minute= %d\n secong= %d”,h,m,s);
getch();
No comments:
Post a Comment