Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
July 25th, 2013, 01:05 PM
 Cantafford
Registered User

Join Date: Jun 2013
Posts: 23
Time spent in forums: 1 h 35 m 16 sec
Reputation Power: 0
Program sorting problem

Basically I wrote this program in which the user enters a number of numbers then each of those number and the program will return the value of the situations in which the maximum value is next to the minimum value or vice-versa.

Code:

#include <stdio.h>
int main()
{
int n, i, nr=0;
float a[100], min, max;
printf("Enter number of values: ");
scanf("%d", &n);
printf("Enter values:\n");
for(i=0; i<n; i++)
scanf("%f", &a[i]); // citirea

min=a[0];
max=a[0];

for(i=0; i<n; i++)
if(a[i]<min) min=a[i];

for(i=0; i<n; i++)
if(a[i]>max) max=a[i];

for(i=0; i<n; i++)
if(a[i]==max && a[i+1]==min || a[i]==min && a[i+1]==max)
nr++;

printf("Number of situations: %d", nr);
getch();
return 0;
}

Now basically I have to modify this program so that it sorts given values in order to have the maximum number of such situations. I tried something but it didn't work unless if there were more than two values verifiying the condition

#2
July 25th, 2013, 02:08 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,865
Time spent in forums: 3 Months 1 Day 7 h 36 m 3 sec
Reputation Power: 2199
Quote:
 Originally Posted by Cantafford I tried something but it didn't work unless if there were more than two values verifiying the condition

OK, I'll wait for information of that to filter through the Astral Plane in the form of telepathic emanations from your mind to my Third Eye chakram. Unfortunately, I'm waiting for my new glasses, so until then I will have greater difficulty focusing my Third Eye. But that's alright. As long as you keep assuming that we can read your mind, we will assume the same thing and wait patiently for it to happen.

And for all the lower-evolved life-forms listening, the secret is to keep banging the rocks together.

#3
August 6th, 2013, 02:54 AM
 Cantafford
Registered User

Join Date: Jun 2013
Posts: 23
Time spent in forums: 1 h 35 m 16 sec
Reputation Power: 0
Quote:
 Originally Posted by dwise1_aol OK, I'll wait for information of that to filter through the Astral Plane in the form of telepathic emanations from your mind to my Third Eye chakram. Unfortunately, I'm waiting for my new glasses, so until then I will have greater difficulty focusing my Third Eye. But that's alright. As long as you keep assuming that we can read your mind, we will assume the same thing and wait patiently for it to happen. And for all the lower-evolved life-forms listening, the secret is to keep banging the rocks together.

The example above, the code which I provided is the case to this.

#4
August 6th, 2013, 10:36 AM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,865
Time spent in forums: 3 Months 1 Day 7 h 36 m 3 sec
Reputation Power: 2199
Did you edit the OP or just double-down on vague?

You "tried something". How are we to divine what that was?
And how are we supposed to know what "it didn't work" is supposed to mean?

IOW, you are expecting us to read your mind and we can't.

Another example:
Quote:
 ... the user enters a number of numbers then each of those number and the program will return the value of the situations in which the maximum value is next to the minimum value or vice-versa.

That is a confused and confusing mess, not an input specification. So now we're supposed to read your mind to determine what input values you're intending to test this with?

Provide us with sample input accompanied by the output that you expect. Then there can be no doubt about what you need. Why must it be such a foreign concept for you?

Until you do provide us with clear information that we need, you're forcing us to either read your mind or play guessing games with you. We do not have time for guessing games.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Program sorting problem