program to make a menu driven and reusable calculator


LIST OF PROGRAMS


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int i=1,a,b,c=0,choice=1;
clrscr();
do
{

switch(i)
{
case 1:
{
printf("enter numbers\n");
scanf("%ld%ld",&a,&b);
printf("enter 1 for add\n");
printf("enter 2 for subtract\n");
printf("enter 3 for multiply\n");
printf("enter 4 for divide\n");
printf("enter 5 for modulus\n");
printf("enter choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:c=a+b;
break;
case 2:c=a-b;
break;
case 3:c=a*b;
break;
case 4:c=a/b;
break;
case 5:c=a%b;
break;
default:printf("wrong input\n");
break;
}
if(choice>0&&choice<6)
printf("%ld",c);
break;
}
}
printf(" enter 1 for re using calculator\n");
printf(" enter other number for exit\n");
scanf("%ld",&i);
}while(i==1);
 printf("thank you\n");
getch();
}

LIST OF PROGRAMS


Comments