-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36_Functions- operations using function add, substract, multply, devide.c
66 lines (57 loc) · 1.83 KB
/
36_Functions- operations using function add, substract, multply, devide.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* WAP that read three variables and pasees and passes them to the function that call and return their sum */
#include<stdio.h>
int main()
{
int a,b,c,sum, substract,multiply,devide;
// Function prototype (Function declaration)----->
int sum_fun(int,int,int); // fun 1:sum
int substract_fun(int,int,int); // fun 2: substract
int multiply_fun(int,int,int); // fun 3: Multiply
int devide_fun(int,int,int); // fun 4: Devide
// taking the input from the user
printf("Enter the values of a, b and c:\n");
scanf("%d%d%d",&a,&b,&c);
// calling the all functions---->
printf("\nCalculation using functions--->\n");
// calling function 1: sum
sum=sum_fun(a,b,c); // calling the function by passing three arguments
printf("\nSum: %d+%d+%d = %d\n",a,b,c,sum);
// calling function 2: substract
substract=substract_fun(a,b,c);
printf("Substract: %d-%d-%d = %d",a,b,c,substract);
// calling function 3: multiply
multiply=multiply_fun(a,b,c);
printf("\nMultiply: %d*%d*%d = %d",a,b,c,multiply);
// calling function 4: devide
devide=devide_fun(a,b,c);
printf("\nDevide: %d/%d/%d = %d",a,b,c,devide);
}
// following is the definaton of the function----->
// Fun 1: sum
int sum_fun(int a1, int b1, int c1) // here a1,b1,c1 are the formal(dummy) arguments
{
int total_sum;
total_sum=a1+b1+c1;
return total_sum;
}
// fun 2: Substract
int substract_fun(int a1, int b1, int c1)
{
int total_substraction;
total_substraction=a1-b1-c1;
return total_substraction;
}
// fun 3: multiply
int multiply_fun(int a1,int b1,int c1)
{
int total_multiply;
total_multiply=a1*b1*c1;
return total_multiply;
}
// // fun 4: devide
int devide_fun(int a1, int b1, int c1)
{
int total_devide;
total_devide=a1/b1/c1;
return total_devide;
}