Question: Write a program that inputs three different integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. Use only the single-selection form of the if statement you learned in this chapter. The screen dialogue should appear as follows:
1 2 |
/* <br /> * Author: AGHATISE OSAZUWA<br /> * Website: www.cscprogrammingtutorials.com <br /> *<br /> * Program that calculate the circumference and area of a circle.<br /> */<br /><br />#include <stdio.h><br />int main ( ){<br /> int num1, num2, num3, sum, ave, prod, min, max;<br /> printf("Enter three numbers: ");<br /> scanf("%d%d%d", &num1, &num2, &num3);<br /> sum = num1 + num2 + num3;<br /> ave = (num1 + num2 + num3) / 3;<br /> prod = num1 * num2 * num3;<br /> printf("Sum is %dn", sum);<br /> printf("Average is %dn", ave);<br /> printf("Product is %dn", prod);<br /> <br /> // Let's assume num1 is the minimum(smallest) number<br /> min = num1; <br /> if (num2 < min){<br /> min = num2;<br /> }<br /> if (num3 < min){<br /> min = num3;<br /> }<br /> printf("Smallest is %dn", min);<br /> <br /> // Let's assume num1 is the maximum(largest) number<br /> max = num1; <br /> if (num2 > max){<br /> max = num2;<br /> }<br /> if (num3 > max){<br /> max = num3;<br /> }<br /> printf("Largest is %dn", max);<br /> return 0;<br />}<br /> |
Program output |
Click here to see other solutions to Deitel C How To Program exercises.