How to write a calculator program in C? | Switch Statement Calculator in C Programming

C Programing Code for Calculator ( INPUT )

#include<stdio.h>
void main()
{
 // C Programing Calculator
 int choice;
 float num1,num2,Result;
printf("Select 1 For Addition\n");
printf("Select 2 For Subtraction\n");
printf("Select 3 For Multiplication\n");
printf("Select 4 For Division\n");
scanf("%d",&choice);
switch (choice)
{
case 1:
printf("Enter First Number\n");
scanf("%f",&num1);
printf("Enter 2nd Number\n");
scanf("%f",&num2);
Result=num1+num2;
printf("Result=%f",Result);
    break;
case 2:
printf("Enter First Number\n");
scanf("%f",&num1);
printf("Enter 2nd Number\n");
scanf("%f",&num2);
Result=num1-num2;
printf("Result=%f",Result);
break;
case 3:
printf("Enter First Number\n");
scanf("%f",&num1);
printf("Enter 2nd Number\n");
scanf("%f",&num2);
Result=num1*num2;
printf("Result=%f",Result);
break;
case 4:
printf("Enter First Number\n");
scanf("%f",&num1);
printf("Enter 2nd Number\n");
scanf("%f",&num2);
Result=num1/num2;
printf("Result=%f",Result);
break;
default:
printf("Invalid Entry\n");
printf("Please Select a Correct Entry");
    break;
}
 getchar();
}

OUTPUT

Select 1 For Addition
Select 2 For Subtraction
Select 3 For Multiplication
Select 4 For Division
4
Enter First Number
23
Enter 2nd Number
11
Result=2.090909[1] + Done

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top