So erstellen Sie Taschenrechner mit Switch in C.
#include <stdio.h>
#include <stdlib.h>
int main()
{
float a,b,s;
char d;
printf("choose an operation btwn + - * / : ");
scanf("%c",&d);
switch(d){
case '+' :
printf("enter two numbers ");
scanf("%f%f",&a,&b);
s = a + b ;
printf("%.1f + %.1f = %.1f",a,b,s);
break;
case '-' :
printf("enter two numbers ");
scanf("%f%f",&a,&b);
s = a - b ;
printf("%.1f - %.1f = %.1f",a,b,s);
break;
case '*' :
printf("enter two numbers ");
scanf("%f%f",&a,&b);
s = a * b ;
printf("%.1f * %.1f = %f",a,b,s);
break;
case '/' :
printf("enter two numbers ");
scanf("%f%f",&a,&b);
s = a / b ;
printf("%.1f / %.1f = %.1f",a,b,s);
break;
default :
printf("enter a valid operation !");
break;
}
return 0;
}
tchenirou