-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex4.1.c
45 lines (38 loc) · 836 Bytes
/
ex4.1.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
#include <stdio.h> //EXERCISE CHAPTER 4 NO 1
//function prototypes for sum, diff and display
void display(int);
int sum(int,int), diff(int,int);
int main ( )
{ int num1, num2, result;
int choice;
printf("Please enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("Now choose what you would like to do:\n ");
printf("1 - Sum, 2 - Difference : ");
scanf("%d", &choice);
if (choice ==1)
{ result = sum(num1, num2);
display (result);
}
else if (choice == 2)
{ result = diff(num1, num2);
display (result);
}
else
printf("Invalid choice\n");
system("pause");
return 0;
}
//function definition for sum, diff and display
int sum(int x, int y)
{
return x+y;
}
int diff(int x, int y)
{
return x-y;
}
void display(int r)
{
printf("The result is: %d\n", r);
}