SIMPLE CALCULATOR


 

A simple calculator program in C language.This used to calculate Arithmetic operations and sum,product,quotient.
Example calculator program is given below:
void help()
{
printf("\n\t\t Calc Version 0.1 \n Choice 1 : Addition \n Choice 2 : Subtraction \n Choice 3 : Product \n Choice 4 : Division \n");
}
void main(int argc,char *argv[])
{
int a=0,b=0,c=0,d=0;
clrscr();
if(argc==1)
{
help();
goto stop;
}
if(argc!=4)
{
printf("\n Less number of arguments supplied! \n Cmd Format : calc \n Thank you for using! - Calc Ver 0.1");
goto stop;
}
a=atoi(argv[1]);
b=atoi(argv[2]);
c=atoi(argv[3]);
switch(a)
{
case 1:d=add(b,c);
printf("\n Sum is %d",d);
break;
case 2:d=sub(b,c);
printf("\n Difference is %d",d);
break;
case 3:d=mult(b,c);
printf("\n Product is %d",d);
break;
case 4:d=div(b,c);
printf("\n Quotient is %d",d);
break;
default:printf("\n Unknown Choice!");
break;
}
stop:
}
NOTE:

  • Calculator program using maths.h.
  • The Help() function is member function .It is used to provide the different operations.

{ 0 comments ... read them below or add one }

Post a Comment