Wednesday, April 19, 2023

create a simple calculator using c programming

  /*create a simple calculator using c programming */

 #include"stdio.h"
 int main (){
double num1,num2,result;
char operator;
printf ("enter two numbers and  type of operator : ");
scanf ("%lf %lf %c",&num1,&num2,&operator );
switch (operator ){
   case '+':
result=num1+num2;
printf ("the result is %lf",result);
break;
   case '-':
result=num1-num2;
printf ("the result is %lf",result);
break;
   case '*':
result=num1*num2;
printf ("the result is %lf",result);
break;
   case '/':
result=num1/num2;
printf ("the result is %lf",result);
break;
default:
printf ("invailed operator ");
}
return 0;
 }

output output output output

enter two numbers and type of operator : 40 20 * the result is 800.000000

No comments:

Post a Comment

print a multiplication table of any integer taking from user

 // print a multiplication table of any integer taking from user  #include "stdio.h" int main () { int n,mul,i; printf ("...