#include<stdio.h>
#include<math.h>
int main()
{
int n1,n2,opt,cnt;
float ang,term,sum,p,r,t,si,ci,a;
printf("A multifunction calculator\n\n");
do
{
clrscr();
printf("\n\n\t\t *******C A L C U L A T O R******\n");
printf("\t\t\t__________________________\n\n");
printf("\t\t\t1). Addition\n");
printf("\t\t\t2). Subtraction\n");
printf("\t\t\t3). Multiplication\n");
printf("\t\t\t4). Division\n");
printf("\t\t\t5). Mod\n");
printf("\t\t\t6). Power\n");
printf("\t\t\t7). Square\n");
printf("\t\t\t8). Square Root\n");
printf("\t\t\t9). sin\n");
printf("\t\t\t10). cos\n");
printf("\t\t\t11). e^x\n");
printf("\t\t\t12). Simple Interest\n");
printf("\t\t\t13). Compound Interest\n");
printf("\t\t\t14). Exit\n");
printf("\t\t\t__________________________\n\n");
printf("\t\t\tEnter your choice= ");
scanf("%d",&opt);
printf("\n");
switch(opt)
{
case 1:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tTotal= %d",n1+n2);
break;
case 2:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tDifference= %d",n1-n2);
break;
case 3:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tMultiplication= %d",n1*n2);
break;
case 4:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
if(n2==0)
printf("\t\t\tERROR!! div by 0");
else
printf("\t\t\tDivison= %0.2f",(float)n1/n2);//type casting
break;
case 5:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
if(n2==0)
printf("\t\t\tERROR!! div by 0");
else
printf("\t\t\tMod= %d",n1%n2);
break;
case 6:
printf("\t\t\tEnter the Base number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the power number= ");
scanf("%d",&n2);
printf("\t\t\tPower= %ld",(long)pow(n1,n2));
break;
case 7:
printf("\t\t\tEnter the no.= ");
scanf("%d",&n1);
printf("\t\t\tSquare= %ld",(long)n1*n1);
break;
case 8:
printf("\t\t\tEnter the no.= ");
scanf("%d",&n1);
printf("\t\t\tSquare= %0.2f",(float)sqrt(n1));
break;
case 9:
printf("\t\t\tEnter the angle of sin");
scanf("%d",&n1);
printf("\t\t\tHow many time to run :");
scanf("%d",&n2);
ang=3.142*n1/180;
for(cnt=1,term=ang,sum=0;cnt<=2*n2-1;cnt+=2)
{
sum=sum+term;
term=-term*ang*ang/((cnt+1)*(cnt+2));
}
printf("\t\t\tsin%d=%f",n1,sum);
break;
case 10:
printf("\t\t\tEnter the angle of cos");
scanf("%d",&n1);
printf("\t\t\tHow many time to run :");
scanf("%d",&n2);
ang=3.142*n1/180;
for(cnt=0,term=ang,sum=0;cnt<2*n2-1;cnt+=2)
{
sum=sum+term;
term=-term*ang*ang/((cnt+1)*(cnt+2));
}
printf("\t\t\tcos%d=%f",n1,sum);
break;
case 11:
printf("\t\t\tEnter the value of x= ");
scanf("%d",&n1);
printf("\t\t\tEnter the Power of x= ");
scanf("%d",&n2);
for(cnt=1,term=1,sum=0;cnt<=n2;cnt++)
{
if(cnt==1)
printf("1");
else
{ sum=sum+term;
term=term*n1/cnt;
}
}
printf("\t\t\tSum of the series is= %0.3f",sum);
break;
case 12:
printf("\t\t\tEnter Principle Amount:");
scanf("%f",&p);
printf("\t\t\tEnter Rate of Interest:");
scanf("%f",&r);
printf("\t\t\tEnter time in years:");
scanf("%f",&t);
si=p*r*t/100;
printf("\t\t\tThe Simple Interest is Rs:%0.2f \n",si);
break;
case 13:
printf("\t\t\tEnter Principle Amount:");
scanf("%f",&p);
printf("\t\t\tEnter Rate of Interest:");
scanf("%f",&r);
printf("\t\t\tEnter time in years:");
scanf("%f",&t);
r=r*0.01;
a=p*pow(1+r,t);
ci=a-p;
printf("\t\t\tThe Compound Interest is Rs.%0.2f",ci);
break;
case 14:
printf("\t\t\t\t\tBye!");
break;
default:
printf("\t\t\t\INVALID CHOICE");
break;
}
} while(opt!=14);
}
#include<math.h>
int main()
{
int n1,n2,opt,cnt;
float ang,term,sum,p,r,t,si,ci,a;
printf("A multifunction calculator\n\n");
do
{
clrscr();
printf("\n\n\t\t *******C A L C U L A T O R******\n");
printf("\t\t\t__________________________\n\n");
printf("\t\t\t1). Addition\n");
printf("\t\t\t2). Subtraction\n");
printf("\t\t\t3). Multiplication\n");
printf("\t\t\t4). Division\n");
printf("\t\t\t5). Mod\n");
printf("\t\t\t6). Power\n");
printf("\t\t\t7). Square\n");
printf("\t\t\t8). Square Root\n");
printf("\t\t\t9). sin\n");
printf("\t\t\t10). cos\n");
printf("\t\t\t11). e^x\n");
printf("\t\t\t12). Simple Interest\n");
printf("\t\t\t13). Compound Interest\n");
printf("\t\t\t14). Exit\n");
printf("\t\t\t__________________________\n\n");
printf("\t\t\tEnter your choice= ");
scanf("%d",&opt);
printf("\n");
switch(opt)
{
case 1:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tTotal= %d",n1+n2);
break;
case 2:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tDifference= %d",n1-n2);
break;
case 3:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
printf("\t\t\tMultiplication= %d",n1*n2);
break;
case 4:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
if(n2==0)
printf("\t\t\tERROR!! div by 0");
else
printf("\t\t\tDivison= %0.2f",(float)n1/n2);//type casting
break;
case 5:
printf("\t\t\tEnter the 1st number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the 2nd number= ");
scanf("%d",&n2);
if(n2==0)
printf("\t\t\tERROR!! div by 0");
else
printf("\t\t\tMod= %d",n1%n2);
break;
case 6:
printf("\t\t\tEnter the Base number= ");
scanf("%d",&n1);
printf("\t\t\tEnter the power number= ");
scanf("%d",&n2);
printf("\t\t\tPower= %ld",(long)pow(n1,n2));
break;
case 7:
printf("\t\t\tEnter the no.= ");
scanf("%d",&n1);
printf("\t\t\tSquare= %ld",(long)n1*n1);
break;
case 8:
printf("\t\t\tEnter the no.= ");
scanf("%d",&n1);
printf("\t\t\tSquare= %0.2f",(float)sqrt(n1));
break;
case 9:
printf("\t\t\tEnter the angle of sin");
scanf("%d",&n1);
printf("\t\t\tHow many time to run :");
scanf("%d",&n2);
ang=3.142*n1/180;
for(cnt=1,term=ang,sum=0;cnt<=2*n2-1;cnt+=2)
{
sum=sum+term;
term=-term*ang*ang/((cnt+1)*(cnt+2));
}
printf("\t\t\tsin%d=%f",n1,sum);
break;
case 10:
printf("\t\t\tEnter the angle of cos");
scanf("%d",&n1);
printf("\t\t\tHow many time to run :");
scanf("%d",&n2);
ang=3.142*n1/180;
for(cnt=0,term=ang,sum=0;cnt<2*n2-1;cnt+=2)
{
sum=sum+term;
term=-term*ang*ang/((cnt+1)*(cnt+2));
}
printf("\t\t\tcos%d=%f",n1,sum);
break;
case 11:
printf("\t\t\tEnter the value of x= ");
scanf("%d",&n1);
printf("\t\t\tEnter the Power of x= ");
scanf("%d",&n2);
for(cnt=1,term=1,sum=0;cnt<=n2;cnt++)
{
if(cnt==1)
printf("1");
else
{ sum=sum+term;
term=term*n1/cnt;
}
}
printf("\t\t\tSum of the series is= %0.3f",sum);
break;
case 12:
printf("\t\t\tEnter Principle Amount:");
scanf("%f",&p);
printf("\t\t\tEnter Rate of Interest:");
scanf("%f",&r);
printf("\t\t\tEnter time in years:");
scanf("%f",&t);
si=p*r*t/100;
printf("\t\t\tThe Simple Interest is Rs:%0.2f \n",si);
break;
case 13:
printf("\t\t\tEnter Principle Amount:");
scanf("%f",&p);
printf("\t\t\tEnter Rate of Interest:");
scanf("%f",&r);
printf("\t\t\tEnter time in years:");
scanf("%f",&t);
r=r*0.01;
a=p*pow(1+r,t);
ci=a-p;
printf("\t\t\tThe Compound Interest is Rs.%0.2f",ci);
break;
case 14:
printf("\t\t\t\t\tBye!");
break;
default:
printf("\t\t\t\INVALID CHOICE");
break;
}
} while(opt!=14);
}
No comments:
Post a Comment