This is in c programming.
The question is not with me right now but its like this, the program wants me to input 10 numbers and then find the average,total,maximum and minimum, Then print back the numbers according from lowest to highest.

I'm having a bit of difficulty doing it with no errors. Help me finish this problem and I'll give you a free domain
Locaton.in ~ gimme your directi@reseller club ID,email.
Thanks

``````#include<stdio.h>
#define N 10
void Max(int num[],int i);
void Min(int num[],int i);
void sort(int num[],int i);

int main()
{
int num[N],i;
float sum=0,average;
for(i=0;i<N;++i)
{
printf("please enter the number that need to be calculate");
printf("\nplease make sure the number is between the 0 and 100\n");
scanf("%d",&num[i]);
}

for(i=0;i<N;++i)
{
printf("the number is %d\n",num[i]);

}
for(i=0;i<N;++i)
{
sum +=num[i];
}
printf("the total value is %.2f\n",sum);
average=(sum/N);
printf("And the average value is %0.2f\n",average);
Max(num,i);
Min(num,i);
sort(num,i);
printf("reorder list of numbers:\n\n");
for(i=0;i<N;++i)
printf("i=%d x=%d\n",i+1,num[i]);
return 0;

}

void Max(int num[],int i)
{
int max = num[0];
for(i=1;i<N;i++)
{
if (max<num[i])
max=num[i];
}
printf("the value of maximum is %d\n",max);

return;
}

void Min(int num[],int i)
{
int min=num[0];
for(i=1;i<N;i++)
{
if (min>num[i])
min=num[i];
}
printf("the value of minimum is %d\n",min);
return;
}

void sort(int num[],int i)
{

int k,temp;
for(k=0;k<N;k++)
{
if(num[k]<num[k+1])
{
temp=num[k+1];
num[k+1]=num[k];
num[k]=temp;
}

return;
}``````

## All 10 Replies

>I'm having a bit of difficulty doing it with no errors.

What do you mean by "...doing it with no errors"?
You are missing the closing bracket for the function sort.
Your formatting needs some work. It is kind of hard to read that way. A guide here.

Yes, you missed the closing bracket of the function sort and wrong in sort algorithm. Here is your function

``````void sort(int num[],int i)
{
int k,k2,temp;
for (int k=0; k<N-1; k++)
for (int k2=k; k2<N; k2++)
if (num[k] > num[k2])
{
temp = num[k];
num[k] = num[k2];
num[k2] = temp;
}
return ;
}``````

``````void sort(int num[],int i)
{
int k,k2,temp;
for (int k=0; k<N-1; k++)
for (int k2=k; k2<N; k2++)
if (num[k] > num[k2])
{
temp = num[k];
num[k] = num[k2];
num[k2] = temp;
}
return ;
}``````

Nope, that's your function, not his. What's the purpose of that int i parameter if it is not used?. And C doesn't allow the declaration of an int type inside of a for loop.

Nope, that's your function, not his. What's the purpose of that int i parameter if it is not used?. And C doesn't allow the declaration of an type inside of a for loop.

Exactly, the "i" paramter is not used in this case.
My puprose is to fix the errors from Wuss to change his sort algorithm and try to unchange the sort prototype.

Due to I am using the gcc to test the code, thanks for your reminder. The following is my modification code:

``````void sort(int num[],int i)
{
int k,k2,temp;
for (k=0; k<N-1; k++)
for (k2=k; k2<N; k2++)
if (num[k] > num[k2])
{
temp = num[k];
num[k] = num[k2];
num[k2] = temp;
}
return ;
}``````

>Exactly, the "i" paramter is not used in this case.
Well, if it is doing nothing don't you think it would be correct to remove it from it?. Perhaps, it could be used as the number of members of the array, instead of using the global constant N ? `for (k2=k; k2<N; k2++)` That part in red wastes a cycle each time in the inner loop. `for (k2 = k + 1; k2 < N; k2++)` saves that extra loop.

well I forgot to edit the last part. now with close } there is no error but there is still problem with agorithm to sort. Anyone can produce my code with the correct algorithm please? I have finish a lot of my time but still have not finish it.

well I forgot to edit the last part. now with close } there is no error but there is still problem with agorithm to sort. Anyone can produce my code with the correct algorithm please? I have finish a lot of my time but still have not finish it.

Just copy and paste. I tested. It ran good.

``````void sort(int num[],int i)
{
int k,k2,temp;
for (k=0; k<N-1; k++)
for (k2=k+1; k2<N; k2++)
if (num[k] > num[k2])
{
temp = num[k];
num[k] = num[k2];
num[k2] = temp;
}
return ;
}``````
commented: For getting it wrong. -3
``````void sort ( int num[], int i )
{
int k, k2, temp;
for ( k = 0; k < N - 1; k++ )
for ( k2 = k + 1; k2 < N; k2++ )
if ( num[k] > num[k2] )
{
temp = num[k];
num[k] = num[k2];
num[k2] = temp;
}
return ;
}``````

What is the point of the end return? etc etc.

What is the point of the end return? etc etc.

To return from the function, probably. :icon_rolleyes: Just because you don't want to be explicit doesn't mean others shouldn't be. And what etc etc? I don't see that anywhere in the code.

xitrum69, you should really have braces around your loops. They make the code easier to read. It is best to be explicit, which causes fewer errors. And a cut/paste of your code doesn't help others learn. It helps them cheat. But pointing them in the right direction does help.

you are not able to print the sorted numbers right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.