-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_calculator.c
More file actions
73 lines (67 loc) · 1.88 KB
/
Copy pathbasic_calculator.c
File metadata and controls
73 lines (67 loc) · 1.88 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<stdlib.h>
void addition(){
int a,b;
printf("enter the first number : ");
scanf("%d",&a);
printf("\nenter the second number: ");
scanf("%d",&b);
int add=a+b;
printf("\nAddition of %d and %d is %d",a,b,add);
}
void subtraction(){
int a,b;
printf("enter the first number : ");
scanf("%d",&a);
printf("\nenter the second number: ");
scanf("%d",&b);
int sub=a-b;
printf("\nSubtraction of %d and %d is %d",a,b,sub);
}
void multiplication(){
int a,b;
printf("enter the first number : ");
scanf("%d",&a);
printf("\nenter the second number: ");
scanf("%d",&b);
int mul=a*b;
printf("\nMultiplication of %d and %d is %d",a,b,mul);
};
void division(){
int div;
int a,b;
printf("enter the first number : ");
scanf("%d",&a);
printf("\nenter the second number: ");
scanf("%d",&b);
if(b==0){
printf("\nERROR");
}else{
div=a/b;
printf("Division of %d and %d is %d",a,b,div);
}
}
int main(){
printf("\n...........................................BASIC CALCULATOR........................................\n");
int choice;
while(choice!=5){
printf("\n1.Addition\n2.Subraction\n3.Multiplication\n4.Division\n5.Exit");
printf("\nenter your choice: ");
scanf("%d",&choice);
printf("\n.....................................................................................................\n");
switch(choice){
case 1:addition();
break;
case 2: subtraction();
break;
case 3:multiplication();
break;
case 4:division();
break;
case 5:exit(0);
break;
default:printf("Invalid choice");
break;
}
}
}