I'm a beginner on C programming so some of you might find the code I'm writing is silly. I have been working for a simple program that ask user for 3 numbers, and provide results such as sum, average, product, smallest and largest number. I come up with this:
Code:
#include<stdio.h>#include<stdlib.h>
int main()
{
int a;
int b;
int c;
printf("Enter number 1: ");
scanf("%d", &a);
printf("Enter number 2: ");
scanf("%d", &b);
printf("Enter number 3: ");
scanf("%d", &c);
printf("\nSum: %d \n", a+b+c);
printf("Average is: %d \n", (a+b+c)/3);
printf("Product is: %d \n", a*b*c);
if(a<b && a<c)
{
printf("Smallest number is: %d \n", a);
}
else if(b<a && b<c)
{
printf("Smallest number is: %d \n", b);
}
else
{
printf("Smallest number is: %d \n", c);
}
if(a>b && a>c)
{
printf("Largest number is: %d \n", a);
}
else if(b>a && b>c)
{
printf("Largest number is: %d \n", b);
}
else
{
printf("Largest number is: %d \n", c);
}
system("pause");
return 0;
}
The problem is whenever I put the same number in number 2 and 3, it automatically choose number 3 as the smallest and the largest number. What am I missing here? Thanks!