Added exercise 3.44
[C-Deitel-Exercises.git] / Chapter-2 / 2-19.c
blob1c2f35b5ffc396fad16c347f81ffac98bbd69f2a
1 /*C How to Program, 6/E, Deitel & Deitel.
3 Solution of exercise 2.19:
4 (Arithmetic, Largest Value and Smallest Value) Write a program that inputs
5 three different integers from the keyboard, then prints the sum, the average,
6 the product, the smallest and the largest of these numbers. Use only the
7 single-selection form of the if statement you learned in this chapter. The
8 screen dialogue should appear as follows:
10 Input three different integers: 13 27 14
11 Sum is 54
12 Average is 18
13 Product is 4914
14 Smallest is 13
15 Largest is 27
17 Written by Juan Carlos Moreno (jcmhsoftware@gmail.com), year 2018.*/
19 #include <stdio.h>
21 int main(void)
23 int a; /*First integer*/
24 int b; /*Second integer*/
25 int c; /*Third integer*/
27 printf("Input three different integers: ");
28 scanf("%d", &a);
29 scanf("%d", &b);
30 scanf("%d", &c);
32 printf("Sum is %d\n", a + b + c);
33 printf("Average is %d\n", (a + b + c)/3);
34 printf("Product is %d\n", a * b * c);
36 /*Print the smallest integer*/
37 if (a < b)
39 if (a < c)
41 printf("Smallest is %d\n", a);
44 if (b < a)
46 if (b < c)
48 printf("Smallest is %d\n", b);
51 if (c < a)
53 if (c < b)
55 printf("Smallest is %d\n", c);
59 /*Print the largest integer*/
60 if (a > b)
62 if (a > c)
64 printf("Largest is %d\n", a);
67 if (b > a)
69 if (b > c)
71 printf("Largest is %d\n", b);
74 if (c > a)
76 if (c > b)
78 printf("Largest is %d\n", c);
82 return 0;