Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.3 kB
2
Indexable
Never
/******************************************************************************

                            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);
   }

}