"Programming made easy" C PROGRAMS BY-
THE ONLY HUB TEAM :) {its viral baby}
Note: We assume that you have just a basic knowledge of the keywords used in the programs enlisted. The Programs will be updated with more, any doubts or discussions about any program can be held in the comment section at the bottom.
1. WAP to print {Hello or anything}:-
#include<stdio.h>
#include<conio.h>/*Including header files*/
void main()
{
clrscr();/*Clears the previous data from output screen */
printf("Hello");/*prints the statement entered in ""*/
getch();/*shows the output screen*/
}
2. WAP to print your details:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Your name\n");/*\n brings the cursor to the new line*/
printf("Your address\n");
getch();
}
3. WAP to addition and subtraction of two numbers:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;/*int type refers for integral numbers*/
clrscr();
printf("Please enter the values of a and b respectively\n");
scanf("%d%d", &a,&b);/*%d is used for int types and & refers to the address of that variable*/
c=a-b;/*Statement to perform the described operation*/
printf("The difference of a and b is %d", c);
d=a+b;
printf("The sum of a and b is %d", d);
getch();
}
4. WAP to perform arithmetic operations like add, sub, division, multiplication:-
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,sum,diff,div,mul;/*float type allows us to print decimal numbers after points*/
clrscr();
printf("Please enter the values of a and b respectively");
scanf("%f%f, &a,&b");/*%f is used for float types*/
sum=a+b;
diff=a-b;
div=a/b;
mul=a*b;
printf("The sum of the numbers is %f\n", sum);
printf("The difference of the numbers is %f\n", diff);
printf("The division of the numbers is %f\n", div);
printf("The product of the numbers is %f\n", mul);
getch();
}
5. WAP to find the area of a triangle/rectangle/circle:-
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,r,a1,a2,a3;
printf("Please enter the length and width");
scanf("%d%d", &l, &b);
/*area of triangle*/a1= 1/2*(l*b);
/*area of rectangle/square*/a2=l*b;
/*area of circle*/a3=3.14*r*r;
printf("The area of the triangle/square/circle is %d", a1/a2/a3);
getch();
6. WAP to enter the marks of subjects and calculate the percentage and average:-
#include<stdio.h>
#include<conio.h>
void main()
{
float eng,hindi,math,phy,chem;
float percentage, avg, sum;
clrscr();
printf("Ënter the marks in English out of 100-");/*Exceeding the marks above 100 will show an error so you are self responsible*/
scanf("%f", &eng);
printf("\nEnter the marks in Hindi out of 100-");
scanf("%f", &hindi);
printf("\nEnter the marks in Maths out of 100-");
scanf("%f", &math);
printf("\nEnter the marks in Physics out of 100-");
scanf("%f", &phy);
printf("\nEnter the marks in Chemistry out of 100-");
scanf("%f", &chem);
sum=eng+hindi+math+phy+chem;
avg=sum/5;
percentage=(sum/500)*100;
printf("\nThe average marks are %f", avg);
printf("\nThe percentage obtained is %f", percentage);
getch();
}
7. WAP to convert the temperature from degree celsius to degree farhenheit:-
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
printf("Enter the temperature in degree Celsius-");
scanf("%f", &c);
f=(9*c)/5+32;
printf("The temperature in degree Farhenheit is %f", f);
printf("The temperature in degree Celsius is %f", c);
getch();
}
8. WAP to calculate the Simple interest of given principle amount, rate and time:-
#include<stdio.h>
#include<conio.h>
void main()
{
int p,r,t,si;
clrscr();
printf("\nPlease enter the Principle amount-");
scanf("%d", &p);
printf("\nPlease enter the rate of interest-");
scanf("%d", &r);
printf("\nPlease enter the time period-");
scanf("%d", &t);
si=(p*r*t)/100;
printf("\nThe Simple Interest of the given data is %d", si);
getch();
}
9.WAP to swap two numbers:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Please enter the nmbers a and b to be swapped-");
scanf("%d%d",a,b);
printf("\nThe number before swapping are %d and %d", a,b);
c=a; // or a=a+b;
a=b;// or b=a-b;
b=c;// or a=a-b;
printf("\nThe numbers after swapping are%d and %d",a,b);
printf("\nHence the numbers are swapped");
getch();
}
10 WAP to check if the number is even or odd:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the number to be checked-");
scanf("%d", &a);
if(a%2=0)//this statement checks if the condition is satisfied
printf("\nThe number entered is an EVEN number");
else//this statement is executed if the condition is not satisfied
printf("\nThe number entered is an ODD number");
getch();
}
11. WAP to check if the number is positive or negative:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Please enter the number to be checked-");
scanf("%d", &a);
if(a>0)
printf("The number is positive\n");
else
printf("The number is negative\n");
getch();
}
12. WAP to find the greatest of 3 Numbers entered by the user:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Please enter the three numbers a,b,c respectively-");
scanf("%d%d%d", &a,&b,&c);
if(a>b && a>c)
printf("\nThe greatest number is %d",a);
else if(b>a && b>c)
printf("\nThe greatest number is %d",b);
else
printf("\nThe greatest number is %d",c);
getch();
}
13. WAP to check if the entered character is Upper case / Lower case/ Digit / Special symbol:-
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf("Please enter the character-");
scanf("%c", &c);
printf("\n The ASCII value of the character entered is %d",a);
if(c>=65 && c<=90)
printf("\nThe character entered is an Upper case letter\n");
else if(c>=97 && c<=122)
printf("The character is a Lower case letter\n");
else if(c>=48 && c<=57)
printf("The character entered is a Digit\n");
else
printf("The character entered is a special symbol")
getch();
}
14. WAP to assign grades according to the result of the student:-
#include<stdio.h>
#include<conio.h>
void main()
{
float eng,hindi,math,phy,chem;
float per, avg, sum;
clrscr();
printf("Ënter the marks in English out of 100-");/*Exceeding the marks above 100 will show an error so you are self responsible*/
scanf("%f", &eng);
printf("\nEnter the marks in Hindi out of 100-");
scanf("%f", &hindi);
printf("\nEnter the marks in Maths out of 100-");
scanf("%f", &math);
printf("\nEnter the marks in Physics out of 100-");
scanf("%f", &phy);
printf("\nEnter the marks in Chemistry out of 100-");
scanf("%f", &chem);
sum=eng+hindi+math+phy+chem;
avg=sum/5;
per=(sum/500)*100;
printf("\nThe average marks are %f", avg);
printf("\nThe percentage obtained is %f", per);
printf("\nALL THE BEST!!")
if(per>=90)
printf("DISTINCTION\n");
else if(per<90 && per>=70)
printf("FIRST Division");
esle if(per<70 && per>=60)
printf("SECOND Division");
else if(per<60 && per>=45)
printf("THIRD Division");
else if(per<45 && per>=33)
printf("PASS");
else
printf("FAIL");
getch();
}
15. WAP to calculate the total salary of a person under given conditions if Basic Salary<=5000, d.a=40% of B.S and r.a=10% of B.S
else d.a=60 % of B.S and r.a=15 % of B.S and hence print the salary
#include<stdio.h>
#include<conio.h>
void main()
{
int bs,da,ra;
clrscr();
printf("Please enter your Basic Salary-");
scanf("%d", &bs);
printf("Your Basic Salary is %d", bs);
if(bs<=5000)
{
printf("da is %d", da=0.4*bs);
printf("ra is %d", ra=0.1*bs);
}
else
{
printf("da is %d", da=0.6*bs);
printf("ra is %d", ra=0.15*bs);
}
getch();
}
THE ONLY HUB TEAM :) {its viral baby}
Note: We assume that you have just a basic knowledge of the keywords used in the programs enlisted. The Programs will be updated with more, any doubts or discussions about any program can be held in the comment section at the bottom.
1. WAP to print {Hello or anything}:-
#include<stdio.h>
#include<conio.h>/*Including header files*/
void main()
{
clrscr();/*Clears the previous data from output screen */
printf("Hello");/*prints the statement entered in ""*/
getch();/*shows the output screen*/
}
2. WAP to print your details:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Your name\n");/*\n brings the cursor to the new line*/
printf("Your address\n");
getch();
}
3. WAP to addition and subtraction of two numbers:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;/*int type refers for integral numbers*/
clrscr();
printf("Please enter the values of a and b respectively\n");
scanf("%d%d", &a,&b);/*%d is used for int types and & refers to the address of that variable*/
c=a-b;/*Statement to perform the described operation*/
printf("The difference of a and b is %d", c);
d=a+b;
printf("The sum of a and b is %d", d);
getch();
}
4. WAP to perform arithmetic operations like add, sub, division, multiplication:-
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,sum,diff,div,mul;/*float type allows us to print decimal numbers after points*/
clrscr();
printf("Please enter the values of a and b respectively");
scanf("%f%f, &a,&b");/*%f is used for float types*/
sum=a+b;
diff=a-b;
div=a/b;
mul=a*b;
printf("The sum of the numbers is %f\n", sum);
printf("The difference of the numbers is %f\n", diff);
printf("The division of the numbers is %f\n", div);
printf("The product of the numbers is %f\n", mul);
getch();
}
5. WAP to find the area of a triangle/rectangle/circle:-
#include<stdio.h>
#include<conio.h>
void main()
{
int l,b,r,a1,a2,a3;
printf("Please enter the length and width");
scanf("%d%d", &l, &b);
/*area of triangle*/a1= 1/2*(l*b);
/*area of rectangle/square*/a2=l*b;
/*area of circle*/a3=3.14*r*r;
printf("The area of the triangle/square/circle is %d", a1/a2/a3);
getch();
6. WAP to enter the marks of subjects and calculate the percentage and average:-
#include<stdio.h>
#include<conio.h>
void main()
{
float eng,hindi,math,phy,chem;
float percentage, avg, sum;
clrscr();
printf("Ënter the marks in English out of 100-");/*Exceeding the marks above 100 will show an error so you are self responsible*/
scanf("%f", &eng);
printf("\nEnter the marks in Hindi out of 100-");
scanf("%f", &hindi);
printf("\nEnter the marks in Maths out of 100-");
scanf("%f", &math);
printf("\nEnter the marks in Physics out of 100-");
scanf("%f", &phy);
printf("\nEnter the marks in Chemistry out of 100-");
scanf("%f", &chem);
sum=eng+hindi+math+phy+chem;
avg=sum/5;
percentage=(sum/500)*100;
printf("\nThe average marks are %f", avg);
printf("\nThe percentage obtained is %f", percentage);
getch();
}
7. WAP to convert the temperature from degree celsius to degree farhenheit:-
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
printf("Enter the temperature in degree Celsius-");
scanf("%f", &c);
f=(9*c)/5+32;
printf("The temperature in degree Farhenheit is %f", f);
printf("The temperature in degree Celsius is %f", c);
getch();
}
8. WAP to calculate the Simple interest of given principle amount, rate and time:-
#include<stdio.h>
#include<conio.h>
void main()
{
int p,r,t,si;
clrscr();
printf("\nPlease enter the Principle amount-");
scanf("%d", &p);
printf("\nPlease enter the rate of interest-");
scanf("%d", &r);
printf("\nPlease enter the time period-");
scanf("%d", &t);
si=(p*r*t)/100;
printf("\nThe Simple Interest of the given data is %d", si);
getch();
}
9.WAP to swap two numbers:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Please enter the nmbers a and b to be swapped-");
scanf("%d%d",a,b);
printf("\nThe number before swapping are %d and %d", a,b);
c=a; // or a=a+b;
a=b;// or b=a-b;
b=c;// or a=a-b;
printf("\nThe numbers after swapping are%d and %d",a,b);
printf("\nHence the numbers are swapped");
getch();
}
10 WAP to check if the number is even or odd:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the number to be checked-");
scanf("%d", &a);
if(a%2=0)//this statement checks if the condition is satisfied
printf("\nThe number entered is an EVEN number");
else//this statement is executed if the condition is not satisfied
printf("\nThe number entered is an ODD number");
getch();
}
11. WAP to check if the number is positive or negative:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("Please enter the number to be checked-");
scanf("%d", &a);
if(a>0)
printf("The number is positive\n");
else
printf("The number is negative\n");
getch();
}
12. WAP to find the greatest of 3 Numbers entered by the user:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Please enter the three numbers a,b,c respectively-");
scanf("%d%d%d", &a,&b,&c);
if(a>b && a>c)
printf("\nThe greatest number is %d",a);
else if(b>a && b>c)
printf("\nThe greatest number is %d",b);
else
printf("\nThe greatest number is %d",c);
getch();
}
13. WAP to check if the entered character is Upper case / Lower case/ Digit / Special symbol:-
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf("Please enter the character-");
scanf("%c", &c);
printf("\n The ASCII value of the character entered is %d",a);
if(c>=65 && c<=90)
printf("\nThe character entered is an Upper case letter\n");
else if(c>=97 && c<=122)
printf("The character is a Lower case letter\n");
else if(c>=48 && c<=57)
printf("The character entered is a Digit\n");
else
printf("The character entered is a special symbol")
getch();
}
14. WAP to assign grades according to the result of the student:-
#include<stdio.h>
#include<conio.h>
void main()
{
float eng,hindi,math,phy,chem;
float per, avg, sum;
clrscr();
printf("Ënter the marks in English out of 100-");/*Exceeding the marks above 100 will show an error so you are self responsible*/
scanf("%f", &eng);
printf("\nEnter the marks in Hindi out of 100-");
scanf("%f", &hindi);
printf("\nEnter the marks in Maths out of 100-");
scanf("%f", &math);
printf("\nEnter the marks in Physics out of 100-");
scanf("%f", &phy);
printf("\nEnter the marks in Chemistry out of 100-");
scanf("%f", &chem);
sum=eng+hindi+math+phy+chem;
avg=sum/5;
per=(sum/500)*100;
printf("\nThe average marks are %f", avg);
printf("\nThe percentage obtained is %f", per);
printf("\nALL THE BEST!!")
if(per>=90)
printf("DISTINCTION\n");
else if(per<90 && per>=70)
printf("FIRST Division");
esle if(per<70 && per>=60)
printf("SECOND Division");
else if(per<60 && per>=45)
printf("THIRD Division");
else if(per<45 && per>=33)
printf("PASS");
else
printf("FAIL");
getch();
}
15. WAP to calculate the total salary of a person under given conditions if Basic Salary<=5000, d.a=40% of B.S and r.a=10% of B.S
else d.a=60 % of B.S and r.a=15 % of B.S and hence print the salary
#include<stdio.h>
#include<conio.h>
void main()
{
int bs,da,ra;
clrscr();
printf("Please enter your Basic Salary-");
scanf("%d", &bs);
printf("Your Basic Salary is %d", bs);
if(bs<=5000)
{
printf("da is %d", da=0.4*bs);
printf("ra is %d", ra=0.1*bs);
}
else
{
printf("da is %d", da=0.6*bs);
printf("ra is %d", ra=0.15*bs);
}
getch();
}
No comments:
Post a Comment