-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek-1_q4.c
49 lines (44 loc) · 1.27 KB
/
week-1_q4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*Q4. Write C program to enter two numbers and
perform all arithmetic operations.*/
#include<stdio.h>
int main(){
int a, b;
char op;
printf("Enter the two operands (Two numbers with a space in between) : \n");
scanf("%d %d", &a, &b);
printf("Enter the operator (+,-,*,/) : \n");
scanf("%c", &op);
scanf("%c", &op);
switch(op){
case '+':
printf("%d + %d = %d", a, b, a+b);
break;
case '-':
printf("%d - %d = %d", a, b, a-b);
break;
case '*':
printf("%d * %d = %d", a, b, a*b);
break;
case '/':
printf("%d / %d = %f", a, b, (float)a/b);
break;
default:
printf("Invalid Input.");
break;
}
return 0;
}
// #include<stdio.h>
// int main(){
// int a, b;
// float c;
// printf("Enter two numbers with a space in between : \n");
// scanf("%d %d", &a, &b);
// c = (float)a/b;
// printf("The sum of the two numbers is : %d \n", (a+b));
// printf("The substraction results : %d \n", (a-b));
// printf("The multiplication results : %d \n", (a*b));
// printf("The division results : %f \n", c);
// printf("The modulo is : %d \n", (a%b));
// return 0;
// }