Jump to content

c programming number sorting

JewishBacon
Go to solution Solved by fizzlesticks,

Assuming I understand the problem, this may help.

float numbers[] = { 43,54,1,64,234,54,23,4,65,3453,234,543,...} // with 500 numbersint main(){	int numValid = 0;	int numInvalid = 0;	float validNumbers[500];	float invalidNumbers[500];	loop through numbers array	{		if the number is 150<x<200		{			add the number to the validNumbers array			add 1 to numValid		}		else 		{			add the number to the invalidNumbers array			add 1 to numInvalid		}	}		//look up qsort for sorting	qsort validNumbers from index 0 to numValid 	qsort invalidNumbers from index 0 to numInvalid	printf validNumbers	printf invalidNumbers	//if the sorted lists need to be printed	loop from 0 to numValid	{		printf validNumber[x]	}	loop from 0 to numInvalid	{		printf invalidNumber[x]	}	return 0;}

im working on a homework assignment for my c programming class. I was given a list of 500 numbers and i have to give a value for how many of them are between 150 and 200.  i think i have most of the program down, but the last thing i need is for the code to go into this list of numbers and assign one at a time to a variable.  my code should then take that variable and sort it. here is a picture of my code. 

 

post-39732-0-83658300-1391569009.png

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

please note that the bottom part of the code

(numbergrabber) is not quite done yet.  

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Are the numbers in a file or hard coded into the program?

they get hard coded into the program

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

im working on a homework assignment for my c programming class. I was given a list of 500 numbers and i have to give a value for how many of them are between 150 and 200.  i think i have most of the program down, but the last thing i need is for the code to go into this list of numbers and assign one at a time to a variable.  my code should then take that variable and sort it. here is a picture of my code. 

 

That is pseudo-code, right? Because there are a lot of errors in there (apart from the obvious "number in question" bit and the part at the end).

 

EDIT: did not see the last reply before posting

How exactly are they hard coded?

Link to comment
Share on other sites

Link to post
Share on other sites

ya ive only been working on it for a few minutes now. but its almost c, im pretty new to all this

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Assuming I understand the problem, this may help.

float numbers[] = { 43,54,1,64,234,54,23,4,65,3453,234,543,...} // with 500 numbersint main(){	int numValid = 0;	int numInvalid = 0;	float validNumbers[500];	float invalidNumbers[500];	loop through numbers array	{		if the number is 150<x<200		{			add the number to the validNumbers array			add 1 to numValid		}		else 		{			add the number to the invalidNumbers array			add 1 to numInvalid		}	}		//look up qsort for sorting	qsort validNumbers from index 0 to numValid 	qsort invalidNumbers from index 0 to numInvalid	printf validNumbers	printf invalidNumbers	//if the sorted lists need to be printed	loop from 0 to numValid	{		printf validNumber[x]	}	loop from 0 to numInvalid	{		printf invalidNumber[x]	}	return 0;}

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

thanks fizz that makes more sense than what i was trying to do!

STEAM NAME: JewishBacon GPU  Sapphire dual x R9 280x OC edition CPU core i7 4770k stock speed COOLER H100i  CASE Fractal R4 Window Black  MOBO MSI gd-65 gaming Storage 1TB WD Blue drive, 1TB Samsung 7200 rpm, 120 GB OCZ SSD, 64 GB WD Blue ssd  RAM 12 GB @ 1600 Ghz kingston RAM  MiscNZXT HUE, disk read/write, 2x 21 inch 1920x1080 monitors   

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×