Untitled

 avatar
unknown
plain_text
3 years ago
1.3 kB
6
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("%c\n",op);
        printf("Enter operation (+,-,*,/): ");
        scanf("%c", &op);
        printf("%c\n",op);

   }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...