Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5de4e77

Browse files
Add files via upload
1 parent f6986e4 commit 5de4e77

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

‎Simple Calculator program in C.c‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Simple Calculator Program in C using Function
2+
#include<stdio.h>
3+
4+
float addFun(float,float);
5+
float subFun(float,float);
6+
float mulFun(float,float);
7+
float divFun(float,float);
8+
9+
int main()
10+
{
11+
float num1,num2,res;
12+
int choice;
13+
do
14+
{
15+
printf("\n|Simple Calculator Program|\n");
16+
printf("\n 1. Addition\n");
17+
printf(" 2. Subtraction\n");
18+
printf(" 3. Multiplication\n");
19+
printf(" 4. Division\n");
20+
printf(" 5. Exit\n\n");
21+
printf("Enter Your Choice(1-5): ");
22+
scanf("%d",&choice);
23+
24+
if(choice>=1&&choice<=4)
25+
{
26+
printf("\nEnter any two Numbers: ");
27+
scanf("%f %f",&num1,&num2);
28+
}
29+
printf("|------------------|");
30+
switch(choice)
31+
{
32+
case 1:
33+
res=addFun(num1,num2);
34+
printf("\n Result = %0.2f",res);
35+
break;
36+
case 2:
37+
res=subFun(num1,num2);
38+
printf("\n Result = %0.2f",res);
39+
break;
40+
case 3:
41+
res=mulFun(num1,num2);
42+
printf("\n Result = %0.2f",res);
43+
break;
44+
case 4:
45+
res=divFun(num1,num2);
46+
printf("\n Result = %0.2f",res);
47+
break;
48+
case 5:
49+
return 0;
50+
default:
51+
printf("\n Wrong Choice!");
52+
break;
53+
}
54+
printf("\n|------------------|\n");
55+
}while(choice!=5);
56+
57+
return 0;
58+
}
59+
float addFun(float a,float b)
60+
{
61+
return(a+b);
62+
}
63+
float subFun(float a,float b)
64+
{
65+
return(a-b);
66+
}
67+
float mulFun(float a,float b)
68+
{
69+
return(a*b);
70+
}
71+
float divFun(float a,float b)
72+
{
73+
return(a/b);
74+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /