How to write a C program to create simple calculator ?
C Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide.
What is Calculator ?
Calculator is something used for making mathematical calculations.Solution:
/* C program to creat simple calculator */
#include <stdio.h>
float add(float a,float b);
float substract(float a,float b);
float multiply(float a,float b);
float divide(float a,float b);
int main(void)
{
float num1,num2;
float w,result=6;
char ch,c;
printf("Enters two numbers to add,substract,multiply or divide\n");
scanf("%f %f",&num1,&num2);
printf("enter a to add, s to substract ,m to multiply,d to divide\n");
scanf("%c %c",&c,&ch);
if(ch=='a'||ch=='A')
{
result=add(num1,num2);
printf("%f\n",result);
}
else if(ch=='s'||ch=='S')
{
result=substract(num1,num2);
printf("%f\n",result);
}
else if(ch=='m'||ch=='M')
{
result=multiply(num1,num2);
printf("%f\n",result);
}
else if(ch=='d'||ch=='D')
{
result=divide(num1,num2);
printf("%f\n",divide(num1,num2));
}
else
{
printf("please input the correct character\n");
}
return 0;
}
float add(float a,float b)
{
float add;
add=a+b;
return add;
}
float substract(float a,float b)
{
float substract;
substract=a-b;
return substract;
}
float multiply(float a,float b)
{
float multiply;
multiply=a*b;
return multiply;
}
float divide(float a,float b)
{
float divide;
divide=(float)a/(float)b;
return divide;
}
simple calculator program in c using switch, simple calculator program in c using switch case, write a c program using switch case, calculator program in c language, switch operation c programming code, c program for simple calculator using switch statement, simple calculator program in java using switch case, simple calculator program in c using functions, simple calculator program in c using graphics
Learn More :
C Program
- Using Bash to input stuff into c program
- Difficult C Programming Questions
- Write a c program to find largest among three numbers using binary minus operator three numbers using binary minus operator
- PRINTING ASCII VALUE USING C PROGRAM
- MULTIPLICATION OF TWO MATRICES USING C PROGRAM
- FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING
- Write A C Program To Find Out Transport Of A Matrix
- Factorial of 100 in C Program
- Multiplication of large numbers in c
- Division of Large Numbers in C Program
- BINARY SEARCH USING C PROGRAM
- BINARY SEARCH THROUGH RECURSION USING C PROGRAM
- FIND FACTORIAL OF A NUMBER USING RECURSION IN C PROGRAM
- FIND GCD OF A NUMBER USING RECURSION IN C PROGRAM
- FIND SUM OF DIGITS OF A NUMBER USING RECURSION USING C PROGRAM
- FIND POWER OF A NUMBER USING RECURSION USING C PROGRAM
- REVERSE A NUMBER USING RECURSION IN C PROGRAM
- SWAP TWO VARIABLES WITHOUT USING THIRD USING C PROGRAM VARIABLE
- Write A C Program For Swapping Of Two Arrays
- SWAPPING OF STRINGS USING C PROGRAM
- CONVERSION FROM DECIMAL TO OCTAL USING C PROGRAM
- CONVERSION FROM DECIMAL TO OCTAL USING C PROGRAM
- CONVERSION OF DECIMAL TO BINARY USING C PROGRAM
- CONVERSION OF FAHRENHEIT TO CENTIGRADE USING C PROGRAM
- C or C++ Program To Find Bonus Amount