→ A simple calculator using C language. In this, you can add, multiply, divide and subtract any two number.
#include<stdio.h>
int main()
{
float a,b,c;
char d;
printf("Enter:");
scanf("%f %c %f",&a,&d,&b);
if(d=='+')
{
c=a+b;
printf("%.2f",c);
}
else if(d=='-')
{
c=a-b;
printf("%.2f",c);
}
else if(d=='*')
{
c=a*b;
printf("%.2f",c);
}
else if(d=='/')
{
c=a/b;
printf("%.2f",c);
}
}
Output: Enter: 9/4
2.25
#include<stdio.h>
int main()
{
float a,b,c;
char d;
printf("Enter:");
scanf("%f %c %f",&a,&d,&b);
if(d=='+')
{
c=a+b;
printf("%.2f",c);
}
else if(d=='-')
{
c=a-b;
printf("%.2f",c);
}
else if(d=='*')
{
c=a*b;
printf("%.2f",c);
}
else if(d=='/')
{
c=a/b;
printf("%.2f",c);
}
}
Output: Enter: 9/4
2.25
Comments
Post a Comment