Skip to main content
Search
Search This Blog
Livecodo
Pages
Home
Courses
Blog
About us
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
March 28, 2024
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,-,*, /, % and use switch statement)
#include
int main() { int a,b; char op; printf("enter the value of op: ",op); scanf("%s",&op); printf("enter the value of a: ",a); scanf("%d",&a); printf("enter the value of b: ",b); scanf("%d",&b); switch(op) { case '+': printf("%d",(a+b)); break; case '-': printf("%d",(a-b)); break; case '/': printf("%d",(a/b)); break; case '%': printf("%d",(a%b)); break; default: printf("Invalid operand!"); } return 0; }
Popular Posts
March 26, 2024
Dynamic Memory allocation in C
May 18, 2024
Searching and sorting Algorithm in C