Program to perform imlpement simple calculator performing basic operations.
#include<stdio.h>
#include<conio.h>
float add(float,float);
float sub(float,float);
float product(float,float);
float divide(float,float);
void main()
{
float n1,n2;
char sym,choice;
clrscr();
printf("Enter the operation you want to perform(Format eg :- 2+3) \n\n");
scanf("%f%c%f",&n1,&sym,&n2);
if(sym=='+')
printf("\n%f",add(n1,n2));
if(sym=='-')
printf("\n%f",sub(n1,n2));
if(sym=='*')
printf("\n%f",product(n1,n2));
if(sym=='/')
printf("%f",divide(n1,n2));
printf("\nDo you wish to continue[y/n]");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
main();
}
float add(float m1,float m2)
{
return(m1+m2);
}
float sub(float m1,float m2)
{
return(m1-m2);
}
float product(float m1,float m2)
{
return(m1*m2);
}
float divide(float m1,float m2)
{
return(m1/m2);
}