Question: Write a program that reads in three integers and then determines and prints the largest and the smallest integers in the group. Use only the programming techniques you have learned in this chapter.
1 2 |
/* <br /> * Author: AGHATISE OSAZUWA<br /> * Website: www.cscprogrammingtutorials.com <br /> *<br /> * Program to calculate and print Largest and Smallest Integers.<br /> */<br /><br />#include <stdio.h><br />int main ( ){<br /> //Program to print largest and smallest numbers.<br /> int num1, num2, num3, min, max;<br /> printf("Enter three integer numbers: ");<br /> scanf("%d%d%d", &num1, &num2, &num3);<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 /> |
Click here to see other solutions to Deitel C How To Program exercises.