Simple C Programs
1. Program to Find Sum and Average of Three Real Numbers.
#include<conio.h>
#include<stdio.h>
void main()
{
float a, b, c, sum, avg;
clrscr();
printf("\nEnter value of three numbers: ");
scanf("%f %f %f", &a, &b, &c);
sum = a + b + c;
avg = sum / 3;
printf("\nSum = %.2f", sum);
printf("\nAverage = %.2f", avg);
getch();
}
| |
2. Program to Find Area of Square and Circumference of a Circle.
#include<stdio.h>
#include<conio.h>
#define PI 3.142
void main()
{
float len, r, area, circum;
clrscr();
printf("\nEnter length of a square: ");
scanf("%f", &len);
area = len * len;
printf("\nEnter radius of a circle: ");
scanf("%f", &r);
circum = 2 * PI * r;
printf("\nArea of square = %.2f", area);
printf("\nCircumference of circle = %.2f", circum);
getch();
}
| |
3.Program to find Sphere Surface Area and Volume of a Sphere.
/* Sphere Surface Area = 4 * PI * r * r
Volume of Sphere = (4/3) * PI * r * r * r
*/
#include<stdio.h>
#include<conio.h>
#define PI 3.142
void main()
{
float r, area, vol;
clrscr();
printf("\nEnter radius of Sphere: ");
scanf("%f", &r);
area = 4 * PI * r * r;
vol = (4/3) * PI * r * r * r;
printf("\nSphere Surface Area = %.2f", area);
printf("\nVolume of Sphere = %.2f", vol);
getch();
}
| |
4. Program to Find Area of a Triangle using Hero Formula.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, s, area;
clrscr();
back:
printf("\nEnter three sides of a triangle: ");
scanf("%f %f %f", &a, &b, &c);
if (a==0 || b==0 || c==0)
{
printf("\nValue of any side should not be equal to zero\n");
goto back;
}
if (a+b
{
printf("\nSum of two sides should not be less than third\n");
goto back;
}
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("\n\nArea of triangle: %.2f", area);
getch();
}
| |
5. Program to Find Simple Interest and Compound Interest.
/* SI = (p * r * t) / 100 CI = p * pow((1 + r/100), t) - p */ #include<stdio.h> #include<conio.h> #include<math.h> void main() { float p, r, t, si, ci; clrscr(); printf("\nEnter priciple, rate and time: "); scanf("%f %f %f", &p, &r, &t); si = (p * r * t) / 100; ci = p * pow((1 + r/100), t) - p; printf("\n\nSimple Interest: %.2f", si); printf("\n\nCompound Interest: %.2f", ci); getch(); } | |
6. Program to Convert Temperature from Degree Centigrade to Fahrenheit.
/* f = (1.8*c) + 32 */ #include<stdio.h> #include<conio.h> void main() { float c, f; clrscr(); printf("\nEnter temperature in degree Centigrade: "); scanf("%f", &c); f = (1.8*c) + 32; printf("\n\nTemperature in degree Fahrenheit: %.2f", f); getch(); } | |
7. Program to Convert Time in Seconds to Hours Minutes and Seconds.
#include<stdio.h> #include<conio.h> void main() { long sec, hr, min, t; clrscr(); printf("\nEnter time in seconds: "); scanf("%ld", &sec); hr = sec/3600; t = sec%3600; min = t/60; sec = t%60; printf("\n\nTime is %ld hrs %ld mins %ld secs", hr, min, sec); getch(); } | |
8. Program to Swap Values of Two Variables using Third Variable.
#include<stdio.h> #include<conio.h> main() { int a, b, temp; clrscr(); printf("\nEnter any two numbers: "); scanf("%d %d", &a, &b); printf("\n\nBefore Swapping:\n"); printf("\na = %d\t b=%d", a,b); temp = a; a = b; b = temp; printf("\n\nAfter Swapping:\n"); printf("\na = %d\t b=%d", a,b); getch(); } | |
9. Program to Swap Values of Two Variables Without using Third Variable.
#include<stdio.h> #include<conio.h> void main() { int a, b, temp; clrscr(); printf("\nEnter any two numbers: "); scanf("%d %d", &a, &b); printf("\n\nBefore Swapping:\n"); printf("\na = %d\t b=%d", a,b); a = a + b; b = a - b; a = a - b; printf("\n\nAfter Swapping:\n"); printf("\na = %d\t b=%d", a,b); getch(); } | |
10. Program to Calculate the Net Salary.
/* Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary(BS+DA+HRA). Program to Calculate the Net Salary. */ #include<stdio.h> #include<conio.h> void main() { float basic_sal, da, hra, pf, gross_sal, net_sal; clrscr(); printf("\nEnter basic salary of the employee: Rs. "); scanf("%f", &basic_sal); da = (basic_sal * 25)/100; hra = (basic_sal * 15)/100; gross_sal = basic_sal + da + hra; pf = (gross_sal * 10)/100; net_sal = gross_sal - pf; printf("\n\nNet Salary: Rs. %.2f", net_sal); getch(); } Control Statements programs in next post........................ |
Great remarkable things here. I'm very satisfied to peer your article. Thank you so much and I'm taking a look ahead to touch you. Will you kindly drop me a e-mail?
ReplyDeleteECCO Men's Track II Low Gore-Tex Oxford
Thank you very much for your comments.
DeleteI am continuously browsing online for tips that can aid me. Thank you!
ReplyDeleteSorel Women's Helen Of Tundra Boot