# Thread: Sum up the largest and smallest ones

1. ## Sum up the largest and smallest ones

Hi!

I am learning C programming and I need some help. In my project I have to enter n numbers and find the smallest and the largest number. AND I DID THIS!

2. You did what?

3. Show us the code you have so far.

4. Originally Posted by iceaway
Show us the code you have so far.
I am sorry, I am the new comer.Next time I will be more careful.

Code:
```#include<stdio.h>
main()
{
int n,m,i,min,max;

scanf("%d",&n);
printf("Enter integers:");
scanf("%d",&m);
max=m;
min=m;
for(i=2;i<=n;i++)
{
scanf("%d",&m);
if(m<min)
min=m;
if(m>max)
max=m;
}
printf("The smallest number is %d\nThe greatest number is %d\n",min,max);
scanf("%d %d",&min,&max);
printf("The sum is : %d\n",min+max);
}```

5. What is line 22 supposed to do? You're overriding your min and max there. Get rid of that and your summation should work correctly.

6. Thank you so much, Dennis.cpp. It works I am so happy!!!!!

7. Do you understand why and what's different now? What had you been trying to achieve with that line 22?

8. Originally Posted by dennis.cpp
Do you understand why and what's different now? What had you been trying to achieve with that line 22?
Yeah , I got it. Because if I use scanf , the program wants new values for min and max. But I already have min and max! So we have to delete scanf! And program takes my first min and max . Is it right?

9. Right.