Untitled
unknown
plain_text
4 years ago
1.2 kB
5
Indexable
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main() { char op; do { op = 'a'; printf("Enter operation (+,-,*,/): "); scanf("%c", &op); while( getchar() != '\n' ); }while(op!='+' && op!='-' && op!='*' && op!='/'); printf("Enter first number: "); int first; scanf("%d", &first); printf("Enter second number: "); int second; scanf("%d", &second); float result; if(op == '+') { result = (float)first + (float)second; printf("Result is %.2f.",result); } else if(op == '-') { result = (float)first - (float)second; printf("Result is %.2f.",result); } else if(op == '*') { result = (float)first * (float)second; printf("Result is %.2f.",result); } else if(op == '/') { result = (float)first / (float)second; printf("Result is %.2f.",result); } }
Editor is loading...