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!:)

But I can not sum up this two values! Could you please help me?

Printable View

- 11-08-2011programmer1Sum 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!:)

But I can not sum up this two values! Could you please help me? - 11-08-2011FloridaJo
You did what?

- 11-08-2011iceaway
Show us the code you have so far.

- 11-08-2011programmer1
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;

printf("Please enter a positive integer:");

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);

}

The sum part can t work. Please help me! - 11-08-2011spaghetticode
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.

- 11-08-2011programmer1
Thank you so much, Dennis.cpp:devil:. It works :devil: I am so happy!!!!!

- 11-08-2011spaghetticode
Do you understand

*why*and what's different now? What had you been trying to achieve with that line 22? - 11-08-2011programmer1
- 11-08-2011spaghetticode
Right. :)