Write a function named Smallest that takes three integer inputs and returns an integer that is the smallest of the three inputs. Write the prototype for the smallest function. Write a program that gets 3 integers from a user and displays the smallest.
Input :
5
6
8
Output :
5
#include <stdio.h>
int Smallest(int x1, int x2, int x3);
int main()
{
int a, b, c, d;
printf("Insert first value: ");
scanf("%d", &a);
printf("Insert second value: ");
scanf("%d", &b);
printf("Insert third value: ");
scanf("%d", &c);
d = Smallest(a, b, c);
printf("The smallest value is %d\n", d);
return 0;
}
int Smallest(int x1, int x2, int x3) {
if (x1 <= x2 && x1 <= x3) {
return x1;
}
if (x2 <= x1 && x2 <= x3) {
return x2;
}
return x3;
}
Comments
Leave a comment