Hello,
I am having a problem with this particular program. The user is prompted to insert 3 numbers (integers). The program should check which of the 3 is the largest and which is the smallest.
At the moment, the program prints one line endlessly:
Code:
printf("Among the numbers you entered");
Code:
#include <stdio.h>
int largest(int large);
int smallest(int small);
int main()
{
int a, /*first input*/
b, /*second input*/
c, /*third input*/
large, /*largest of a, b and c*/
small; /*smallest of a, b and c*/
printf("Enter 3 integers with a space in between : ");
scanf("%d %d %d", &a, &b, &c);
/*if a is the largest*/
if((a > b) && (a > c))
{
a = large;
largest(large);
/*if a is the largest and b the smallest*/
if(b < c)
{
b = small;
smallest(small);
}
/*if a is the largest and c the smallest*/
else if(c < b)
{
c = small;
smallest(small);
}
}
/*if b is the largest*/
else if((b > a) && (b > c))
{
b = large;
largest(large);
/*if b is the largest and a the smallest*/
if(a < c)
{
a = small;
smallest(small);
}
/*if b is the largest and c the smallest*/
else if(c < a)
{
c = small;
smallest(small);
}
}
/*if c is the largest*/
else if((c > a) && (c > b))
{
c = large;
largest(large);
/*if c is the largest and a the smallest*/
if(a < b)
{
a = small;
smallest(small);
}
/*if c is the largest and b the smallest*/
else if(b < a)
{
b = small;
smallest(small);
}
}
return 0;
}
int largest(int large)
{
printf("Among the numbers you entered");
printf("\nthe largest was %d and the smallest was ", largest(large));
}
int smallest(int small)
{
printf("%d.", smallest(small));
}