C Source Codes List | Source Code Home
Program : Program for calculator simulation.
#include
#include
void main()
{
int i,d,k,a,r,h;
char m='y';
long s,n1,n2;
clrscr();
printf("\ncalculation ?");
scanf("%c",&m);
while(m=='Y'||m=='y')
{
clrscr();
printf("\n1.factorial\n2.addition\n3.subtraction\n4.multiplication\n5.division
\n6.squares\n7.exit\nenter your choice .......");
scanf("\n%d",&d);
while(d>7||d<1)
scanf("\n%d",&d);
switch (d)
{
case 1:
clrscr();
printf("enter any positive manageable number");
scanf("%d",&a);
while (a<0)
scanf("%d",&a);
k=1;
for(i=1;i<=a;i++)
k=k*i;
printf("factorial is %d",k);getch();
break;
case 2:
clrscr();
printf("enter any two numbers");
scanf(" %ld %ld",&n1,&n2);
s=n1+n2;
printf("sum of the input numbers is %ld",s);
getch();
break;
case 3:
clrscr();
printf("enter any number");
scanf("%ld,%ld",&n1,&n2);
s=n1-n2;
printf("the difference between the two numbers is %ld",s);
getch();
break;
case 4:
clrscr();
printf("enter any numbers which are to be multilied");
scanf(" %ld,%ld",&n1,&n2);
s=n1*n2;
printf("the product is %ld",s);
getch();
break;
case 5:
clrscr();
printf("enter dividend");
scanf("%d",&n1);
printf("enter divisor ");
scanf("%d",&n2);
while (n2==0)
{
scanf("%d",&n1);
scanf("%d",&n2);
}
s=n1/n2;
printf("the quotient is %d",s);
getch();
break;
case 6:
clrscr();
printf("enter the number whose square is to be found out");
scanf(" %d",&n1);
s=n1*n1;
printf("the square of the number is %d",s);
getch();
break;
case 7:
exit();
default: printf("\n\nError");
}
printf("another calculation");
scanf(" %c",&m);
}
}
C Source Codes List | Source Code Home
|
|