NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help My Homework & I'll give you a .in domain!

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-11-2008, 05:11 PM THREAD STARTER               #1 (permalink)
Senior Member
 
wussadotcom's Avatar
Join Date: Jan 2008
Posts: 1,591
wussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant future
 




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


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;
}
__________________
[HOT!] | Laman Web Cinta
I recommend Janine for high quality designs!!
FLIPPA
wussadotcom is offline  
Old 08-11-2008, 08:09 PM   #2 (permalink)
NamePros Member
 
el_paon's Avatar
Join Date: Apr 2006
Posts: 58
el_paon is on a distinguished road
 



I'll give it a try right now.
el_paon is offline  
Old 08-11-2008, 09:12 PM   #3 (permalink)
NamePros Member
Join Date: Sep 2006
Posts: 99
Bruce_KD will become famous soon enoughBruce_KD will become famous soon enough
 



Your sort algorithm is flawed.
Consider an array with 4 elements (just for simplification)
????: NamePros.com http://www.namepros.com/programming/502732-help-my-homework-ill-give-you.html

[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 by Bruce_KD; 08-11-2008 at 09:20 PM.
Bruce_KD is offline  
Old 08-11-2008, 10:13 PM THREAD STARTER               #4 (permalink)
Senior Member
 
wussadotcom's Avatar
Join Date: Jan 2008
Posts: 1,591
wussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant future
 




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!
__________________
[HOT!] | Laman Web Cinta
I recommend Janine for high quality designs!!
FLIPPA
wussadotcom is offline  
Old 08-11-2008, 11:17 PM   #5 (permalink)
NamePros Member
 
el_paon's Avatar
Join Date: Apr 2006
Posts: 58
el_paon is on a distinguished road
 



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.
el_paon is offline  
Old 08-12-2008, 12:59 AM THREAD STARTER               #6 (permalink)
Senior Member
 
wussadotcom's Avatar
Join Date: Jan 2008
Posts: 1,591
wussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant futurewussadotcom has a brilliant future
 




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
__________________
[HOT!] | Laman Web Cinta
I recommend Janine for high quality designs!!
FLIPPA
wussadotcom is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:58 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger