Source code of simple calculator that performs addition, subtraction, multiplication and division operations. So lets start.😃
// Program for calculator
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,add,sub;
float c,d,multiply,divide;
clrscr();
printf("Enter which operation you want to perform");
printf("\n 1.Addition \n 2.Subtraction \n 3.Multiplication \n 4.Division \n");
int option;
printf("Enter your choice :: ");
scanf("%d",&option);
switch(option)
{
case 1:
printf("\nEnter the numbers: ");
scanf("%d \t %d",&a,&b);
add=a+b;
printf("%d",add);
break;
case 2:
printf("\nEnter the numbers: ");
scanf("%d \t %d",&a,&b);
sub=a-b;
printf("%d",sub);
break;
case 3:
printf("\n Enter the numbers: ");
scanf("%f \t %f",&c,&d);
multiply=c*d;
printf("%f",multiply);
break;
case 4:
printf("\n Enter the numbers: ");
scanf("%f \t %f",&c,&d);
divide=c/d;
printf("%f",divide);
break;
default:
printf("Invalid choice");
break;
}
getch();
}
0 Comments