-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple-Calculator.c
More file actions
45 lines (44 loc) · 879 Bytes
/
Copy pathSimple-Calculator.c
File metadata and controls
45 lines (44 loc) · 879 Bytes
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
#include <stdio.h>
#include <conio.h>
void main()
{
//simple calculator
int n, n1, n2;
char c;
printf("Welcome to simple Calculator\n");
scanf("%d %c %d", &n, &c, &n1);
if (n == 0 && c == '/' && n1 == 0)
{
printf("Undefined");
}
else if (c == '/' && n1 == 0)
{
printf("Cannot divide by zero");
}
else
{
switch (c)
{
case '+':
n2 = n + n1;
printf("%d", n2);
break;
case '-':
n2 = n - n1;
printf("%d", n2);
break;
case '*':
n2 = n * n1;
printf("%d", n2);
break;
case '/':
n2 = n / n1;
printf("%d", n2);
break;
default:
printf("Something went wrong");
break;
}
}
getch();
}