Sunday, September 12, 2010
Some Examples of C Progarms
1. Write a program to display the word “Hello”.
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Hello”)
getch();
}
2. Write a program to display Name and address of a person.
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Name”)
Printf(“Address;)
getch();
}
3. Write a program to display four cities of our country Nepal.
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Kathnamdu\n Nepaljunj\n Pokhara\n Biratnagar”)
getch();
}
4. Write a program to calculate two numbers sum.
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, sum;
clrscr();
printf(“Input the First number”);
scanf(“%d”, &a);
printf(“Input the Second number’);
scanf(“%d”, &b);
sum=a*b;
printf(“sum of the two number”);
getch();
}
5. Write a program to input Length and breadth of the room and calculate perimeter and area of the room.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,b,perimeter,area;
clrscr();
printf(“ Input the length”);
scanf(%d”, &l);
printf(“ Input the breadth”);
scanf( “%d”, &b);
area= l*b;
perimater=2*(l+b);
printf(“ Area of the room=%d\n”,area);
printf(“ Perimater of the room=%d”, perimeter);
getch();
}
6. Write a program to calculate Area of the circle.
#include <stdio.h>
#include <conio.h>
void main()
{
float r, area;
clrscr();
printf(“ Input the radious of the circle”);
scanf(“%f”, &r);
area=3.14*r*r
printf(“Area of the circle=%f”,area);
getch();
}
7. Write a program to input Principal, rate and time. Calculate the simple interest.
#include <stdio.h>
#include <conio.h>
void main()
{
int p,r,t,si;
clrscr();
printf(“Input principal”);
scanf(“%d”, &p);
printf(“Input rate”);
scanf(“%d”, &r);
printf(“Input time”);
scanf(“%d”, &t);
si=p*t*r/100;
printf(“Simple Interest=%d”,si);
getch();
}
8. Write a program to input two numbers and display Quotation and reminder. Where (a) is divisible by (b).
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,quo,rem;
clrscr();
printf(“Input first subject”);
scanf(“%d”, &a);
printf(“Input second subject”);
scanf(“%d”, &b);
quo=a/b;
rem=a%b;
printf(“Quotation=%d\n Reminder=%d”,quo,rem);
getch();
}
9. Write a program to input Marks of 5 subjects and calculate the total and percentage.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d,e,total,per;
clrscr();
printf(“Input first subject”);
scanf(“%d”, &a);
printf(“Input second subject”);
scanf(“%d”, &b);
printf(“Input third subject”);
scanf(“%d”, &c);
printf(“Input fourth subject”);
scanf(“%d”, &d);
printf(“Input fifth subject”);
scanf(“%d”, &e);
total=a+b+c+d+e;
per=total/5
printf(“total=%d and Percentage=%d”,total,per);
getch();
}
11. Write a program to input Length in km and display in meter, centimeter and millimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,m,cm;
clrscr();
printf(“Input lngth in km”);
scanf(“%d”, &l);
m=l*1000;
cm=l*1000*100; (m*100)
mm=l*1000*100*10; (cm*10)
printf(“Meter=%d\n centimeter=%d
\n millimeter=%d”,m,cm,mm);
getch();
}
12. Write a program to input a time in minutes and display it in the hour and minutes.
#include <stdio.h>
#include <conio.h>
void main()
{
int t, hr, min;
clrscr();
printf(“Input time in minute”);
scanf(“%d”, &t);
hr=t/60
min=t%60
printf(“Time=%d hr and %d min”,hr,min);
getch();
}
13. Write a program to input time in second and display it in the hour and minutes.
#include <stdio.h>
#include <conio.h>
void main()
{
int t, hr, min sec, remsec;
clrscr();
printf(“Input time in minute”);
scanf(“%d”, &t);
hr=t/3600;
remsec=t%3600;
min=remsec/60;
sec=remsec%60;
printf(“Time=%d hr and %d min”,hr,min);
getch();
}
14. Write a program to input Length in cm and display in kilometer, meter and centimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,km,m,cm;
clrscr();
printf(“Input lngth in cm”);
scanf(“%d”, &l);
km=l/100000;
l=l%100000;
m=l/1000;
cm=l%1000;
printf(“Length=%d km, %dm, and %dcm”,km,m,cm;
getch();
}
15. Write a program to input number of days and convert it into year, month and days.
#include <stdio.h>
#include <conio.h>
void main()
{
int day,yrs,remday;
clrscr();
printf(“Input number of days”);
scanf(“%d”, &day);
yrs=day/365;
remday=day%365
mth=day/30;
day=day%30;
printf(“Days=%dyrs, %dmth, %dday”,yrs,mth,day);
getch();
}
16. Write a progam to input two digit number and display its reverse.
#include <stdio.h>
#include <conio.h>
void main()
{
int ab, quo, rem, rev;
clrscr();
printf(“Input two digits number”);
scanf(“%d”, &ab);
quo=ab/10;
` rem=ab%10;
rev=rem+quo;
printf(“reverse=%d”,rev);
getch();
}
17. Write a progam to input two digit number and display its sum.
#include <stdio.h>
#include <conio.h>
void main()
{
int ab, quo, rem, sum;
clrscr();
printf(“Input two digits number”);
scanf(“%d”, &ab);
quo=ab/10;
` rem=ab%10;
sum=rem+quo;
printf(“Sum=%d”,sum);
getch();
}
18. Write a program to input Length in mm and display in kilometer, meter, centimeter and millimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,km,m,cm,mm;
clrscr();
printf(“Input lngth in mm”);
scanf(“%d”, &l);
km=l/100000;
l=l%100000;
m=l/1000;
cm=l%1000;
printf(“Length=%d km, %dm, and %dcm” ,km,m,cm,mm);
getch();
}
19. Write a program to input the age of the person and display the person is eligible for voting or nor.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf(“Input age of the person”);
scanf(“%d”, &n);
if(n>=18)
{
printf(“The person is eligible for voting”);
}
else
{
printf(“The person is not eligible foe voting”);
}
getch();
}
20. Write a program to input a number and display if the number is divisible by 5 or not
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf(“Input age of the number”);
scanf(“%d”, &n);
if(n/5==0)
{
printf(“Number is divisible by 5”);
}
else
{
printf(“Number is not divisible by 5”);
}
getch();
}
21. Write a program to input two numbers and display the largest among them.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf(“Input two numbers”);
scanf(“%d%d”, &a, &b);
if(a>b)
{
printf(“%d is the largest”, a);
}
Else if(b>a)
{
printf(“%d is the largest”, b);
}
else
printf(“%d and %d are equal”, a,b);
}
getch();
}
22. Write a program to input C.P. and S.P. of a product and display eighter profit or lost.
#include <stdio.h>
#include <conio.h>
void main()
{
int cp,sp;
clrscr();
printf(“Input sp of the product”);
scanf(“%d”, &sp);
if(sp>cp)
{
printf(“%d is profit”,sp);
}
Else if (cp>sp)
{
printf(“%d is loss”, cp);
}
Else
{
Printf(“%d and %d are equal”,sp,cp);
}
getch();
}
23. Write a program to input C.P. and S.P. of a product and display eighter profit or lost amount.
#include <stdio.h>
#include <conio.h>
void main()
{
int cp,sp,profit,loss;
clrscr();
printf(“Input sp and cp of the product”);
scanf(“%d%d”, &sp, &cp);
if(sp>cp)
{
Profit=sp-cp;
printf(“Profit Amount=%d”,profit);
}
Else if (cp>sp)
{
printf(“Loss Amount=%d “, loss);
}
Else
{
Printf(“Neither profit nor Loss”);
}
getch();
}
24. Write a program to input sales of a day and calculate the commission amount on the basis of the sales on following condition: >20,000=20% commission, >=10,000=10%comision,
Other wise, 5% commission.
#include <stdio.h>
#include <conio.h>
void main()
{
float s,com;
clrscr();
printf(“Input sales amount of the day”);
scanf(“%f”, &s);
if(s>20000)
{
Com=0.2*s;
printf(“ Commission Amount=%f”, com);
}
Else if (s>=10000)
{
Com=0.1*s;
printf(“Commission Amount=%f”, com);
}
Else if(s<10000)
{
Com=0.05*s;
Printf(“Commission Amount=%f”,com);
}
getch();
}
25. Write a progam ti input mark of 5 subject and calculate and display total, percentage and division.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d,e,total,per,div0;
clrscr();
printf(“Input the mark of Fist Subject”);
scanf(“%d”, &a);
printf(“Input the mark of Second Subject”);
scanf(“%d”, &b);
printf(“Input the mark of Third Subject”);
scanf(“%d”, &c);
printf(“Input the mark of Fourth Subject”);
scanf(“%d”, &d);
printf(“Input the mark of Fifth Subject”);
scanf(“%d”, &e);
total=a+b+c+d+e;
per=total/5;
if(per>=75)
{
printf(“Distinction”);
}
Else if (per>=60)
{
printf(“First”);
}
Else if (per>=50)
{
Printf(“Second”);
Else if (per>=35)
{
Printf(“Third”);
}
Else
{
Printf(“Fail”);
}
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Hello”)
getch();
}
2. Write a program to display Name and address of a person.
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Name”)
Printf(“Address;)
getch();
}
3. Write a program to display four cities of our country Nepal.
#include <stdio.h>
#include <conio.h>
void main()
{
Clrscr();
Printf(“Kathnamdu\n Nepaljunj\n Pokhara\n Biratnagar”)
getch();
}
4. Write a program to calculate two numbers sum.
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, sum;
clrscr();
printf(“Input the First number”);
scanf(“%d”, &a);
printf(“Input the Second number’);
scanf(“%d”, &b);
sum=a*b;
printf(“sum of the two number”);
getch();
}
5. Write a program to input Length and breadth of the room and calculate perimeter and area of the room.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,b,perimeter,area;
clrscr();
printf(“ Input the length”);
scanf(%d”, &l);
printf(“ Input the breadth”);
scanf( “%d”, &b);
area= l*b;
perimater=2*(l+b);
printf(“ Area of the room=%d\n”,area);
printf(“ Perimater of the room=%d”, perimeter);
getch();
}
6. Write a program to calculate Area of the circle.
#include <stdio.h>
#include <conio.h>
void main()
{
float r, area;
clrscr();
printf(“ Input the radious of the circle”);
scanf(“%f”, &r);
area=3.14*r*r
printf(“Area of the circle=%f”,area);
getch();
}
7. Write a program to input Principal, rate and time. Calculate the simple interest.
#include <stdio.h>
#include <conio.h>
void main()
{
int p,r,t,si;
clrscr();
printf(“Input principal”);
scanf(“%d”, &p);
printf(“Input rate”);
scanf(“%d”, &r);
printf(“Input time”);
scanf(“%d”, &t);
si=p*t*r/100;
printf(“Simple Interest=%d”,si);
getch();
}
8. Write a program to input two numbers and display Quotation and reminder. Where (a) is divisible by (b).
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,quo,rem;
clrscr();
printf(“Input first subject”);
scanf(“%d”, &a);
printf(“Input second subject”);
scanf(“%d”, &b);
quo=a/b;
rem=a%b;
printf(“Quotation=%d\n Reminder=%d”,quo,rem);
getch();
}
9. Write a program to input Marks of 5 subjects and calculate the total and percentage.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d,e,total,per;
clrscr();
printf(“Input first subject”);
scanf(“%d”, &a);
printf(“Input second subject”);
scanf(“%d”, &b);
printf(“Input third subject”);
scanf(“%d”, &c);
printf(“Input fourth subject”);
scanf(“%d”, &d);
printf(“Input fifth subject”);
scanf(“%d”, &e);
total=a+b+c+d+e;
per=total/5
printf(“total=%d and Percentage=%d”,total,per);
getch();
}
11. Write a program to input Length in km and display in meter, centimeter and millimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,m,cm;
clrscr();
printf(“Input lngth in km”);
scanf(“%d”, &l);
m=l*1000;
cm=l*1000*100; (m*100)
mm=l*1000*100*10; (cm*10)
printf(“Meter=%d\n centimeter=%d
\n millimeter=%d”,m,cm,mm);
getch();
}
12. Write a program to input a time in minutes and display it in the hour and minutes.
#include <stdio.h>
#include <conio.h>
void main()
{
int t, hr, min;
clrscr();
printf(“Input time in minute”);
scanf(“%d”, &t);
hr=t/60
min=t%60
printf(“Time=%d hr and %d min”,hr,min);
getch();
}
13. Write a program to input time in second and display it in the hour and minutes.
#include <stdio.h>
#include <conio.h>
void main()
{
int t, hr, min sec, remsec;
clrscr();
printf(“Input time in minute”);
scanf(“%d”, &t);
hr=t/3600;
remsec=t%3600;
min=remsec/60;
sec=remsec%60;
printf(“Time=%d hr and %d min”,hr,min);
getch();
}
14. Write a program to input Length in cm and display in kilometer, meter and centimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,km,m,cm;
clrscr();
printf(“Input lngth in cm”);
scanf(“%d”, &l);
km=l/100000;
l=l%100000;
m=l/1000;
cm=l%1000;
printf(“Length=%d km, %dm, and %dcm”,km,m,cm;
getch();
}
15. Write a program to input number of days and convert it into year, month and days.
#include <stdio.h>
#include <conio.h>
void main()
{
int day,yrs,remday;
clrscr();
printf(“Input number of days”);
scanf(“%d”, &day);
yrs=day/365;
remday=day%365
mth=day/30;
day=day%30;
printf(“Days=%dyrs, %dmth, %dday”,yrs,mth,day);
getch();
}
16. Write a progam to input two digit number and display its reverse.
#include <stdio.h>
#include <conio.h>
void main()
{
int ab, quo, rem, rev;
clrscr();
printf(“Input two digits number”);
scanf(“%d”, &ab);
quo=ab/10;
` rem=ab%10;
rev=rem+quo;
printf(“reverse=%d”,rev);
getch();
}
17. Write a progam to input two digit number and display its sum.
#include <stdio.h>
#include <conio.h>
void main()
{
int ab, quo, rem, sum;
clrscr();
printf(“Input two digits number”);
scanf(“%d”, &ab);
quo=ab/10;
` rem=ab%10;
sum=rem+quo;
printf(“Sum=%d”,sum);
getch();
}
18. Write a program to input Length in mm and display in kilometer, meter, centimeter and millimeter.
#include <stdio.h>
#include <conio.h>
void main()
{
int l,km,m,cm,mm;
clrscr();
printf(“Input lngth in mm”);
scanf(“%d”, &l);
km=l/100000;
l=l%100000;
m=l/1000;
cm=l%1000;
printf(“Length=%d km, %dm, and %dcm” ,km,m,cm,mm);
getch();
}
19. Write a program to input the age of the person and display the person is eligible for voting or nor.
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf(“Input age of the person”);
scanf(“%d”, &n);
if(n>=18)
{
printf(“The person is eligible for voting”);
}
else
{
printf(“The person is not eligible foe voting”);
}
getch();
}
20. Write a program to input a number and display if the number is divisible by 5 or not
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf(“Input age of the number”);
scanf(“%d”, &n);
if(n/5==0)
{
printf(“Number is divisible by 5”);
}
else
{
printf(“Number is not divisible by 5”);
}
getch();
}
21. Write a program to input two numbers and display the largest among them.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf(“Input two numbers”);
scanf(“%d%d”, &a, &b);
if(a>b)
{
printf(“%d is the largest”, a);
}
Else if(b>a)
{
printf(“%d is the largest”, b);
}
else
printf(“%d and %d are equal”, a,b);
}
getch();
}
22. Write a program to input C.P. and S.P. of a product and display eighter profit or lost.
#include <stdio.h>
#include <conio.h>
void main()
{
int cp,sp;
clrscr();
printf(“Input sp of the product”);
scanf(“%d”, &sp);
if(sp>cp)
{
printf(“%d is profit”,sp);
}
Else if (cp>sp)
{
printf(“%d is loss”, cp);
}
Else
{
Printf(“%d and %d are equal”,sp,cp);
}
getch();
}
23. Write a program to input C.P. and S.P. of a product and display eighter profit or lost amount.
#include <stdio.h>
#include <conio.h>
void main()
{
int cp,sp,profit,loss;
clrscr();
printf(“Input sp and cp of the product”);
scanf(“%d%d”, &sp, &cp);
if(sp>cp)
{
Profit=sp-cp;
printf(“Profit Amount=%d”,profit);
}
Else if (cp>sp)
{
printf(“Loss Amount=%d “, loss);
}
Else
{
Printf(“Neither profit nor Loss”);
}
getch();
}
24. Write a program to input sales of a day and calculate the commission amount on the basis of the sales on following condition: >20,000=20% commission, >=10,000=10%comision,
Other wise, 5% commission.
#include <stdio.h>
#include <conio.h>
void main()
{
float s,com;
clrscr();
printf(“Input sales amount of the day”);
scanf(“%f”, &s);
if(s>20000)
{
Com=0.2*s;
printf(“ Commission Amount=%f”, com);
}
Else if (s>=10000)
{
Com=0.1*s;
printf(“Commission Amount=%f”, com);
}
Else if(s<10000)
{
Com=0.05*s;
Printf(“Commission Amount=%f”,com);
}
getch();
}
25. Write a progam ti input mark of 5 subject and calculate and display total, percentage and division.
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d,e,total,per,div0;
clrscr();
printf(“Input the mark of Fist Subject”);
scanf(“%d”, &a);
printf(“Input the mark of Second Subject”);
scanf(“%d”, &b);
printf(“Input the mark of Third Subject”);
scanf(“%d”, &c);
printf(“Input the mark of Fourth Subject”);
scanf(“%d”, &d);
printf(“Input the mark of Fifth Subject”);
scanf(“%d”, &e);
total=a+b+c+d+e;
per=total/5;
if(per>=75)
{
printf(“Distinction”);
}
Else if (per>=60)
{
printf(“First”);
}
Else if (per>=50)
{
Printf(“Second”);
Else if (per>=35)
{
Printf(“Third”);
}
Else
{
Printf(“Fail”);
}
getch();
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment