of x

# Programming (Case Study) - CSU

Published on 2 weeks ago | Categories: Documents | Downloads: 0 | Comments: 0
90 views

## Content

Joio Franz C Gianan #3

Write a program that gives the choice of computing any of the following: the area of a circle, a square, a rectangle, or a triangle. The program should include a loop to allow the user to do as many calculations a desired. Assume the 1 2 3 4 5

following options: Area of circle Area of square Area of rectangle Area of triangle Exit

#include<stdio.h> void main() { int Choice=0; float pi=3.14; float ac=0; float as=0; float ar=0; float at=0; float r=0; float s=0; float l=0; float float w=0; b=0; float h=0; printf("1 printf("2 printf("3 printf("4 printf("5

-

Area of circle\n"); Area of square\n"); Area of rectangle\n"); rectangle\n") ; Area of triangle\n"); Exit\n\n");

printf("Choice:"); scanf("%d", &Choice);

Joio Franz C Gianan #3

while(Choice<=4) { if(Choice==1) { printf("Enter radius:"); scanf("%f", &r); ac=pi*r*r; printf("Area of circle:%.2f\n\n", ac); printf("1 printf("2 printf("3 printf("4 printf("5

-

Area of circle\n"); Area of square\n"); Area of rectangle\n"); rectangle\n"); Area of triangle\n"); Exit\n\n");

printf("Choice:"); scanf("%d", &Choice); } { if(Choice==2) { printf("Enter side:"); scanf("%f", &s); as=s*s; printf("Area of square:%.2f\n\n", as); printf("1 printf("2 printf("3 printf("4 printf("5

-

Area of circle\n"); Area of square\n"); Area of rectangle\n") rectangle\n"); ; Area of triangle\n"); Exit\n\n");

printf("Choice:"); scanf("%d", &Choice); } { if(Choice==3) { printf("Enter length:"); scanf("%f", &l); printf("Enter width:"); scanf("%f", &w); ar=l*w; printf("Area of rectangle:%.2f\n\n", ar);

Joio Franz C Gianan #3

printf("1 printf("2 printf("3

-

Area of circle\n"); Area of square\n"); Area of rectangle\n rectangle\n"); ");

printf("4 printf("5

-

Area of triangle\n" triangle\n"); ); Exit\n\n");

printf("Choice:"); scanf("%d", &Choice); } { if(Choice==4) { printf("Enter base:"); scanf("%f", &b); printf("Enter height:"); scanf("%f", &h); at=(b*h)/2; printf("Area of triangle:%.2f\n\n", at); printf("1 printf("2 printf("3 printf("4 printf("5

-

Area of circle\n"); Area of square\n"); Area of rectangle\n") rectangle\n"); ; Area of triangle\n"); Exit\n\n");

printf("Choice:"); scanf("%d", &Choice); } } } } } }

Hide