|
|
Write a menu based program which allows users to calculate the
area and perimeter of the following shapes :
|
|
#include <stdio.h> int main(void) { char choice; do { printf("\n\'C\'ircle\n\'T\'riangle\n\'R\'ectangle\n\'S\'quare\n\'E\'xit\nChoice :"); fflush(stdin); scanf("%c", &choice); switch(choice) { case 'c': case 'C': { float radius; printf("Enter the radius :"); scanf("%f", &radius); printf("\nArea of circle is %f", 3.14 * radius * radius); printf("\nPerimeter of circle is %f", 2 * 3.14 * radius); break; } case 't': case 'T': { float base, ht; printf("Enter the base and height :"); scanf("%f%f", &base, &ht); printf("\nArea of triangle is %f", 0.5 * base * ht); break; } case 'r': case 'R': { float length, breadth; printf("Enter the length and breadth :"); scanf("%f%f", &length, &breadth); printf("\nArea of rectangle is %f", length * breadth); printf("\nPerimeter of rectangle is %f", 2 * (length + breadth)); break; } case 's': case 'S': { float side; printf("Enter the side :"); scanf("%f", &side); printf("\nArea of square is %f", side * side); printf("\nPerimeter of square is %f", 4 * side); break; } default : printf("\nInvalid choice"); } }while(choice != 'E' && choice != 'e'); return 0; }
|
|
|
|
|
|
|
|