-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathparjanyahkcprog.c
48 lines (38 loc) · 947 Bytes
/
parjanyahkcprog.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
/*C program to design a simple calculator with basic operations.*/
#include <stdio.h>
#include <conio.h>
int main()
{
int num1,num2;
float res;
char ch;
printf("Enter first number: ");
scanf("%d",&num1);
printf("Enter second number: ");
scanf("%d",&num2);
printf("Choose operation to perform (+,-,*,/,%): ");
scanf(" %c",&ch);
res=0;
switch(ch)
{
case '+':
res=num1+num2;
break;
case '-':
res=num1-num2;
break;
case '*':
res=num1*num2;
break;
case '/':
res=(float)num1/(float)num2;
break;
case '%':
res=num1%num2;
break;
default:
printf("Invalid operation.\n");
}
printf("Result: %d %c %d = %f\n",num1,ch,num2,res);
return 0;
}