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?
This is a discussion on Sum up the largest and smallest ones within the C Programming forums, part of the General Programming Boards category; Hi! I am learning C programming and I need some help. In my project I have to enter n numbers ...
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?
You did what?
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; 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!
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.
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3
Thank you so much, Dennis.cpp. It works
I am so happy!!!!!
Do you understand why and what's different now? What had you been trying to achieve with that line 22?
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3
Right.![]()
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3