I would like you to do is create a console application that will either add, subtract or divide two numbers. The Program will have four functions one to add, subtract, multiply and divide the two numbers. The user will enter the two number and the +, -, *, / symbol and the program will display the appropriate result.
#include<stdio.h> int add(int a, int b){ return a+b; } int subtrace(int a, int b){ return a-b; } int mul(int a, int b){ return a*b; } int div(int a, int b){ return a/b; } int main() { int a,b; char ch; printf("Please enter two numbers separated by space: "); scanf("%d %d",&a,&b); printf("Enter one operator +, -, *, /: "); scanf("%c",&ch); scanf("%c",&ch); switch(ch){ case '+': printf("The sum is %d\n",add(a,b)); break; case '-': printf("The difference is %d\n",subtrace(a,b)); break; case '*': printf("The product is %d\n",mul(a,b)); break; case '/': printf("The quotient is %d\n",div(a,b)); break; default: printf("Invalid operator\n"); } return 0; }
Get Answers For Free
Most questions answered within 1 hours.