On 25 Dec 2006 13:44:50 -0800, "iskeletor" <zi********@gmail.com>
wrote:
>i want to have integers from user and take them into a array then
sorting them but where do i make mistake?thanx from now
#include <stdio.h>
#include <stdlib.h>
int number=0,count=0,numberArray[100];
int main (){
int a;
Sort(numberArray);
At this point, Sort is an unknown function. You should either code a
prototype for it (right after the #include directives) or place the
code for main after the code for Sort.
for(a=0;a<count;a++){
printf("%ld\t",numberArray[a]);
%ld is not suitable for an int in printf.
}
return 0;
}
int Sort(int array[]){
You have confused yourself by having the Sort function also perform
the input. It would be better to separate the two tasks in different
functions.
int temp,z,t;
printf("Enter a positive integer(To exit enter -1)\n");
scanf("%ld",&number);
%ld is not suitable for an int in scanf either.
while(number!=-1){
numberArray[count]=number;
//printf("numberArray[%ld]=%ld",count,numberArray[count]);
// comments can wrap when posted, preventing others from compiling
your code.
count++;
After the first number, count will be 1.
printf("Enter a positive integer(To exit enter -1)\n");
scanf("%ld",&number);
You probably meant to terminate the while loop at this point. You
certainly don't want to sort the array after each number is input.
This is an example of how consistent indenting can really help you.
printf("%d\n",count);
for(t=0;t<count;++t){
t is 0, count is 1.
for(z=t+1;t<count+1;++z){
t does not change in this loop so the loop will never end. Did you
mean z<count+1? As written, z will be 1.
You might also consider a little horizontal white space to make things
easier to read.
if(array[t]>array[z]){
array[1] contains 0 (it was initialized because the array is at file
scope. It does not contain a number input to the program by the user.
You are sorting numbers you don't have yet.
temp=array[t];
array[t]=array[z];
array[z]=temp;
}
}
}
}//while loop ends
Too late.
>}
Remove del for email