Stimulate calculator using Switch-case-default statement for
two numbers
Answer / Anil Kumar Ojha
Here's a simple example in C:
```c
#include <stdio.h>
void main() {
int num1, num2, choice;
printf("Enter two numbers:n");
scanf("%d %d", &num1, &num2);
printf("Enter operation number:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentn");
scanf("%d", &choice);
switch(choice) {
case 1: printf("%d + %d = %d", num1, num2, num1 + num2); break;
case 2: printf("%d - %d = %d", num1, num2, num1 - num2); break;
case 3: printf("%d * %d = %d", num1, num2, num1 * num2); break;
case 4: if(num2 != 0) printf("%d / %d = %f", num1, num2, (float)num1 / num2); else printf("Error! Division by zero is not allowed."); break;
case 5: printf("%d mod %d = %d", num1, num2, num1 % num2); break;
case 6: printf("%d ^ %d = %d", num1, num2, pow(num1, num2)); break;
default: printf("Invalid operation number. Please enter a valid option.");
}
}
```
This code prompts the user to input two numbers and choose an operation, then it calculates the result using a switch-case statement.
| Is This Answer Correct ? | 0 Yes | 0 No |
what is pointer ? what is the use of pointer?
How to write c functions that modify head pointer of a linked list?
What is the difference between procedural and declarative language?
f(x,y,z) { y = y+1; z = z+x; } main() { int a,b; a = 2 b = 2; f(a+b,a,a); print a; } what is the value of 'a' printed
Determine the code below, tell me exactly how many times is the operation sum++ performed ? for ( i = 0; i < 100; i++ ) for ( j = 100; j > 100 - i; j--) sum++;
How are variables declared in c?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
Will Macros support multiple arguments ?
Which is better pointer or array?
diff between exptected result and requirement?
Does c have function or method?
what is linkage error when it occurs in c program