M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Recent Posts
Categories
- Others (2)
- Programming (11)
- C Programming (11)
Archives
- September 2011 (6)
- August 2011 (7)
This program displays a menu and makes use of switch-case statement to process the selected option.
/*This program finds the area of some basic geometric shapes*/ #include<stdio.h> #include<conio.h> void main() { int op=0,l=0,b=0,r=0,h=0,area=0; clrscr(); printf("Find Area of the following:\nSelect an option[1,2,3,4]:\n"); printf("1.Square\n"); printf("2.Rectangle\n"); printf("3.Circle\n"); printf("4.Triangle\n"); scanf("%d",&op); switch(op) { case 1: printf("Enter side:"); scanf("%d",&l); area=l*l; printf("Area:%d",area); break; case 2: printf("Enter length:"); scanf("%d",&l); printf("Enter breadth:"); scanf("%d",&b); area=l*b; printf("Area:%d",area); break; case 3: printf("Enter radius:"); scanf("%d",&r); area=3.14*r*r; printf("Area:%d",area); break; case 4: printf("Enter base:"); scanf("%d",&b); printf("Enter height:"); scanf("%d",&h); area=0.5*b*h; printf("Area:%d",area); break; default: printf("Please select an option from the above list"); } getch(); }
Output
Find Area of the following: Select an option[1,2,3,4]: 1.Square 2.Rectangle 3.Circle 4.Triangle 1 Enter side:8 Area:64