Advertisement
touhid_xml

Simple C Calculator

May 31st, 2014
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. /************
  2. Simple C calculato Program by Touhid
  3. Dedicated for Tareq
  4. *************/
  5. #include <stdio.h>
  6. int calc(int x, int y, char o);
  7. int main(void){
  8.     int a,b,sum;  // a for first number , b for second number and sum = a  + b
  9.    
  10.     char o; //operator
  11.  
  12.     printf("Enter the first number: ");
  13.    
  14.     //input for first number
  15.     scanf("%d",&a);
  16.     printf("\nEnter the operator: ");
  17.    
  18.     // input for the operator
  19.     scanf("%s",&o);
  20.    
  21.     printf("\nEnter the second number: ");
  22.    
  23.     // input for the second number
  24. scanf("%d",&b);
  25.  
  26.     // calculate the result according as character variable "o
  27. switch(o){
  28. case '+':
  29. sum = a + b;
  30. break;
  31. case '-':
  32. sum = a - b;
  33. break;
  34. case '*':
  35. sum = a * b;
  36. break;
  37. case '/':
  38. sum = a / b;
  39. break;
  40. default:
  41. sum = NULL;
  42. }
  43.  
  44. // display the result
  45. printf("\nTotal is: %d", sum);
  46. getch();   
  47. return 0;  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement