C program (MENU DRIVEN) to find the area of circle, triangle, equilateral triangle, right angled triangle, rectangle, square, trapezium, rhombus and parallelogram.
#include <stdio.h> #include<conio.h> #include <stdlib.h> #include <math.h> int main() { float area, s; int a, b, c, length, breath, height, radius, side, ch; clrscr(); while(1) { /* get the option from user */ printf("1. Circle\t2. Triangle\n"); printf("3. Rectangle\t4. Square\n"); printf("5. Trapezoid\t6. Rhombus\n"); printf("7. Parallelogram\t8.Equilateral triangle \n"); printf("9.aright angled triangle\t10.Exit\n"); printf("Enter your choice:"); scanf("%d", &ch);
switch(ch) { case 1: printf("Enter the radius of the circle:"); scanf("%d", &radius); area = 3.14 * radius * radius;
printf("Area of Circle: %f\n", area); break;
case 2: printf("Enter the sides of the triangle:"); scanf("%d%d%d", &a, &b, &c); s = (1.0 * (a + b + c)) / 2; area = sqrt(s * (s - a) * (s - b) * (s - c)); printf("Area of Triangle: %f\n", area); break;
case 3: printf("Enter the length and breath of Rectangle:"); scanf("%d%d", &length, &breath); area = length * breath; printf("Area of Rectangle: %f\n", area); break;
case 4: printf("Enter the side of a square:"); scanf("%d", &side); area = side * side; printf("Area of square: %f\n", area); break;
case 5: printf("Enter the length of parallel sides(a & b):"); scanf("%d%d", &a, &b); printf("Enter the height:"); scanf("%d", &height); area = ((a + b) * 1.0 * height) / 2; printf("Area of trapezoid: %f\n", area); break;
case 6: printf("Enter the diagonal values(p & q):"); scanf("%d%d", &a, &b); area = a * b / 2; printf("Area of rhombus: %f\n", area); break;
case 7: printf("Enter the breath and height of parallelogram:"); scanf("%d%d", &b, &height); area = b * height * 1.0 / 2; printf("Area of parallelogram: %f\n", area); break;
case 8: printf("Enter the side of a Equilateral triangle:"); scanf("%d", &a); area = (sqrt(3)/4)*(a*a); printf("Area of Equilateral triangle: %f\n", area); break;
case 9: printf("Enter the value of a and b for right angled triangle:"); scanf("%d%d", &a,&b); area = (1/2)*(a*b); printf("Area of right angled triangle: %f\n", area); break;
case 10: exit(0);
default: printf("Wrong Option!!\n"); break; } getch(); return 0; } } OUTPUT: 1. Circle 2. Triangle 3. Rectangle 4. Square 5. Trapezoid 6. Rhombus 7. Parallelogram 8.Equilateral triangle 9.aright angled triangle 10.Exit Enter your choice: 2 Enter the size of the triangle: 2 5 6 Area of Triangle: 4.683749
C program (menu driven) to find the volume and surface area of cube, cuboids, cylinder, cone, sphere and hemi-sphere
#include <stdio.h> #include<conio.h> #include <stdlib.h> #include <math.h> int main() { float v,sa; int a,l,b,h,ch,r,s; clrscr(); while(1) { /* get the option from user */ printf("1. Cube\t2. Cuboid\n"); printf("3. Cylinder\t4. Cone\n"); printf("5. Sphere\t6. Hemi-sphere\n"); printf("7. Exit\n");
printf("Enter your choice:"); scanf("%d", &ch); switch(ch) { case 1: printf("Enter the value of a for cube:"); scanf("%d", &a); v=a*a*a; sa=6*a*a*a*a*a*a; printf("Surface Area of Cube: %f\n", sa); printf("\nVolumn of Cube: %f\n",v); break;
case 2: printf("\nEnter the value of l,h and b for cuboid:"); scanf("%d%d%d",&l,&h,&b); v=l*h*b; sa=(2*l*h)+(2*h*b)+(2*b*l); printf("Surface Area of Cuboid: %f\n", sa); printf("\nVolumn of Cuboid: %f\n",v);
break;
case 3: printf("\nEnter the value of r and h for Cylinder:"); scanf("%d%d",&r,&h); v=3.14*r*r*h; sa=(2*3.14*r*r)+(2*3.14*r*h); printf("Surface Area of Cylinder: %f\n", sa); printf("\nVolumn of Cylinder: %f\n",v);
break;
case 4: printf("\nEnter the value of r, h and s for Cone:"); scanf("%d%d%d",&r,&h); v=(1/3)*3.14*r*r*h; sa=(3.14*r*s)+(3.14*r*r); printf("Surface Area of Cone: %f\n", sa); printf("\nVolumn of Cone: %f\n",v);
break;
case 5: printf("\nEnter the value of r for Sphere:"); scanf("%d%d",&r,&h); v=(4/3)*3.14*r*r*r; sa=4*3.14*r*r; printf("Surface Area of Sphere: %f\n", sa); printf("Volumn of Sphere: %f\n",v);
break;
case 6:
printf("\nEnter the value of r for Hemi-Sphere:"); scanf("%d%d",&r,&h); v=(2/3)*3.14*r*r*r; sa=2*3.14*r*r; printf("Surface Area of Hemi-Sphere: %f\n", sa); printf("Volumn of Hemi-Sphere: %f\n",v);
C program to check whether a number is EVEN or ODD #include<stdio.h> #include<conio.h> main() { int number; clrscr(); printf("Enter any integer: "); scanf("%d", &number); if(number%2==0) printf("%d is even number.",number); else printf("%d is odd number.",number); getch(); return 0; }
C program to find quotent and remainder of 2 integers: #include<stdio.h> #include<conio.h> main() { int n,t,quot,rem; clrscr(); printf("\nEnter two numbers: \t"); scanf("%d%d",&n,&t); quot=(n/t); rem=(n%t); printf("Quotient is: %d",quot); printf("Remainder is: %d", rem); getch(); return 0; }
C program to find average of 3 integers ( average of 3 numbers) #include<stdio.h> #include<conio.h> main() { int n,s,r,avg; clrscr(); printf("\nEnter 3 numbers : \t"); scanf("%d%d%d",&n,&s,&r); avg=(n+s+r)/3; printf("\nAverage of 3 numbers is: %d ", avg); getch(); return 0; }
Program to print square of a number given by the user #include<stdio.h> #include<conio.h> main() { int n,sq; clrscr(); printf("\nEnter a number:\t"); scanf("%d",&n); sq=n*n; printf("Result: %d",sq); getch(); return 0; } OUTPUT: Enter a number: 3 Result: 9