Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************
- Simple C calculato Program by Touhid
- Dedicated for Tareq
- *************/
- #include <stdio.h>
- int calc(int x, int y, char o);
- int main(void){
- int a,b,sum; // a for first number , b for second number and sum = a + b
- char o; //operator
- printf("Enter the first number: ");
- //input for first number
- scanf("%d",&a);
- printf("\nEnter the operator: ");
- // input for the operator
- scanf("%s",&o);
- printf("\nEnter the second number: ");
- // input for the second number
- scanf("%d",&b);
- // calculate the result according as character variable "o
- switch(o){
- case '+':
- sum = a + b;
- break;
- case '-':
- sum = a - b;
- break;
- case '*':
- sum = a * b;
- break;
- case '/':
- sum = a / b;
- break;
- default:
- sum = NULL;
- }
- // display the result
- printf("\nTotal is: %d", sum);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement