[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
Go Back  Xtreme Visual Basic Talk > > > [C] - sorted numbers plus 1 info


Reply
 
Thread Tools Display Modes
  #1  
Old 02-17-2013, 10:10 AM
Cambalinho_83's Avatar
Cambalinho_83 Cambalinho_83 is offline
Senior Contributor
 
Join Date: Feb 2008
Location: somewhere in space
Posts: 1,296
Default [C] - sorted numbers plus 1 info


i'm trying understand, in code, how can i sorted the numbers. heres the code, but i lose some numbers
Code:
#include <stdio.h>

int idades[5];

void main()
{
	int i;
	int a;
	
	//insert the ages
	for (i=0;i<5;i++)
	{
		printf("Insert your age: ");
		scanf("%d", &idades[i]);	
	}
	
	//sorted the ages
	int b;
	for (i=0;i<10;i++)
	{		
		
			if (idades[i]>idades[i+1])
			{				
				for (a=i;idades[a]>idades[a+1];a++)
				{
					

					b=idades[a];
					idades[a]=idades[a+1];
					idades[a+1]=b;
					
				}			
			}

			
		
	}
	
	for (i=0;i<5;i++)
	{
		printf("Sorted ages: %d\n", idades[i]);
			
	}
}
but problem is here:
Code:
	//sorted the ages
	int b;
	for (i=0;i<10;i++)
	{		
		
			if (idades[i]>idades[i+1])
			{				
				for (a=i;idades[a]>idades[a+1];a++)
				{
					

					b=idades[a];
					idades[a]=idades[a+1];
					idades[a+1]=b;
					
				}			
			}

			
		
	}
when the number is more big than next, then move it. but the number ins't moved and i lose some
(i need understand what isn't right)
can anyone advice me?
Reply With Quote
Reply


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info [C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
 
[C] - sorted numbers plus 1 info
[C] - sorted numbers plus 1 info
 
-->