Unstoppable Domains โ€” Expired Auctions

Help My Homework & I'll give you a .in domain!

SpaceshipSpaceship
Watch

wussadotcom

My MemoriesVIP Member
Impact
58
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

Code:
#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;
}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I'll give it a try right now.
 
0
•••
Your sort algorithm is flawed.
Consider an array with 4 elements (just for simplification)

[2,5,3,6]

0 - [5, 2, 3, 6]
1 - [5, 3, 2, 6]
2 - [5, 3, 6, 2]
Wait... 3 is still less than 4. But num[3 + 1] doesn't exist! Oh noe!
Plus, there is the fact that it still leaves them out of order.

O(n) is a wonderful outcome for a sorting algorithm. Perhaps even the Holy Grail of Computer Science. However, this is not the way to do it :(
Lets settle for Bubble Sort, O(n^2)!

Code:
int[] sort(int[] nums) {
  int tmp, i, j;
  for (i=0; i<N-1; i++) {
    for (j=0; j<N-1-i; j++) {
      if (nums[j+1] < nums[j]) {  
        tmp = nums[j+1];      
        nums[j+1] = nums[j];
        nums[j] = tmp;
      }
    }
  }
  return nums;
}

Edit:
Also, like I say below, I'm not a C guy. However, I'm pretty sure you need to return the array (nums), then set the original array to the sorted one, then print that.


Bruce

P.S. I don't actually know C, I'm a Java guy. But this is definitely flawed. There might be more errors though.
 
Last edited:
0
•••
Thanks Bruce @ Java lover, but I still don't get it :( Produce a running code please anyone, mwzd is waiting to push the domain to you now(well I bought it from him):)

oh yeah, I forgot to add closing } so there is no error now but still the arranging is off!
 
0
•••
Here's a working code, post if you have any questions.

Code:
#include<stdio.h>
#define N 10



int main(int argc, char *argv[])
{
int Max(int num[]);
int Min(int num[],int i);
void sort(int num[]);



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

printf("\nyou have entered %d/%d\n" , i+1,N);
}

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);
printf("the value of maximum is %d\n",Max(num));
printf("the value of minimum is %d\n",Min(num,N));
sort(num);
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;

}

int Max(int num[])
{
int max = num[0];
int i;
for(i=1;i<N;i++)
{
	if (max<num[i])
		max=num[i];
}


return max;
}

int Min(int num[],int k)
{
int min=num[N-k];
int i;
for(i=N-k+1;i<N;i++)
{
	if (min>num[i])
		min=num[i];
}

return min;
}


void sort(int num[])
{

int k,i,temp;

for(k=0;k<N;k++)
    {
        for(i=k;i<N;i++)
            {
                if(num[i]==Min(num,N-k))
                    {
                        temp=num[k];
                        num[k]=num[i];
                        num[i] = temp;
                        break;
                    }

            }
    }

return;

}

I have edited the Min and Sort functions.
 
0
•••
ok. I'll check it later as I am in class rite now. PM me ur directi also.thanks

ok. thanks. please send me your directi username and email. cheers
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Spaceship
Domain Recover
CatchDoms
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back