C Program: Make a Calculator that Calculates Area of different Figures by using switch Statement

Calculator

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int fig_code;

float radius ;                                            /* For Circle */
float length , breadth ;                              /* For Rectangle */
float base , height ;                                   /* For Triangle */
float side ;                                               /* For Square */
float base1 , height1 ;                               /* For parallelogram */
float base2 , base3 , height2 ;                    /* For Trapezoid */
                                            

printf("................../n");
printf("1 Circle\n");
printf("2 Rectangle\n");
printf("3 Triangle\n");
printf("4 Square\n");
printf("5 Parallelogram\n");
printf("6 Trapezoid\n");
printf(" Enter the Figure code\n");
scanf("%d" , &fig_code\n");
switch(fig_code)
{
  Area of Circle
case1:                                                                                  
printf("Enter the Radius\n");
scanf("%f" , &radius);
Area= 3.142*radius*radius;
printf("Area of Circle = %f\n" , Area);
break;
                                                                                            
Area of Rectangle
case 2:
printf("Enter the breadth and length\n");                           
scanf("%f%f" ,&breadth, &length);
Area= breadth*length;
printf("Area of Rectangle = %f\n" , Area);
break;

Area of Triangle
case 3:                                                              
printf("Enter the base and height\n");                     
scanf("%f%f" , &base , &height);                                  
area= 0.5*base*height;                                                           
printf("Area of Triangle = %f\n" , area);
break;

Area of Square
case 4:
printf("Enter the Side\n");
scanf("%f" , &side);                                                         
area= side*side;
printf("Area of Square = %f\n" , area);
break;
                                                                               
Area of Parallelogram
case 5:
printf("Enter the base1 and height1\n");                           
scanf("%f%f" , &base1 , &height1 );            
Area= base1 * height1;
printf("Area of Parallelogram = %f\n" , Area);
break;

Area of Trapezoid

case 6:
printf("Enter the base2 , base3 and height2\n");                           
scanf("%f%f" , &base1 , &base2 , &height1 );                         
Area=0.5*( base1 + base2 ) * height2;
printf("Area of Trapezoid = %f\n" , Area);
break;

default:
printf("Error in the figure code\n");
break;

}                                             /* End of switch */
}                                             /* End of main() */

Output:
....................
1 Circle
2 Rectangle
3 Triangle
4 Square
5 Parallelogram
6 Trapezoid
....................
Enter the Figure Code
4
Enter the side
2
Area of a square = 4



                                                   Did you check the following?                                                
                                         
                            C Program: Make a Calculator by using switch Statement


0 Response to "C Program: Make a Calculator that Calculates Area of different Figures by using switch Statement"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag