-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc05.c
More file actions
31 lines (28 loc) · 759 Bytes
/
c05.c
File metadata and controls
31 lines (28 loc) · 759 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
//simple calculator using if else
#include<stdio.h>
int main()
{
float a,b; int ch;
float x;
printf("enter 1st number: ");
scanf("%f", &a);
fflush(stdin); // optional, compiler-specific
printf("enter 2nd number: ");
scanf("%f", &b);
fflush(stdin); // optional, compiler-specific
x=(float)(a/b);
printf("1-->add\n2--.subtract\n3-->multiply\n4-->divide\nenter your choice: ");
scanf("%d", &ch);
fflush(stdin); // optional, compiler-specific
if(ch==1)
printf("addition=%f",a + b);
else if(ch==2)
printf("subtraction=%f",a - b);
else if(ch==3)
printf("multiplication=%f",a * b);
else if(ch==4)
printf("division=%f",x);
else
printf("inavlid choice");
return 0;
}