Headlines
Loading...
C Program to function for a calculator

C Program to function for a calculator

Program to function for a calculator

 #include<stdio.h>

#include<conio.h>

void main()

{

int ch ,a,b;

float res;

clrscr();

printf("\n1:Addition");

printf("\n2:Subtraction");

printf("\n3:Multiplication");

printf("\n4:Division");

while(1)

{

printf("\nEnter two numbers:");

scanf("%d %d",&a,&b);

printf("\nEnter the choice:");

scanf("%d",&ch);

switch(ch)

{

case 1:

res=a+b;

printf("\nAddition is %0.0f: ",res);

break;

 

case 2:

res=a-b;

printf("\nSubtraction is %0.0f: ",res);

break;

 

case 3:

res=a*b;

printf("\nMultiplication is %0.0f: ",res);

break;

 

case 4:

res=a/b;

printf("\nDivision is %0.0f: ",res);

break;

 

default:

printf("exit");

exit();

}

}

getch();

}

/**************OUTPUT**************

1:Addition

2:Subtraction

3:Multiplication

4:Division

Enter two numbers:2 3

 

Enter the choice:1

Addition is 5:

Enter two numbers:5 4

 

Enter the choice:3

 

Multiplication is 20:

Enter two numbers:3 8

 

Enter the choice:5

exit                            */

 

 

 


*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***