program help: array sort odd & even numbers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

program help: array sort odd & even numbers

shaieenshaieen Posts: 20Member
i ran the program but it have errors. kindly check them huh? thanks!!
and..

please add codes for this to the program:

[b]if a negative number is encountered, the program prompts the user" Negative number encountered" and ask for another input.

[/b]


#include
#include
void main(){

int a[10],b[10],c[10],i,j=0,k=0;
clrscr();

printf("Enter 10 positive numbers:
");
for(i=0;i<10;i++){
scanf("%d",&a[i]);}
for(i=0;i<10;i++){
if((a[i]%2)==0){
b[j]=a[i];j++;}
else{
c[k]=a[i];
k++;
}
}

printf("The even numbers are:
");
for (i=0;[color=Red]i<j-1[/color];j++)}
printf("%d
",b[i]);
}
printf("The odd numbers are:
");
for(i=0;[color=Red]i<k-1[/color];i++){
printf("%d
",c[i]);}
getch();


}

Comments

  • Malcolm_McLeanMalcolm_McLean Posts: 254Member ✭✭
    Call qsort() with a function that makes odd numbers lower in the comparison rank than even ones.

    (It's not an efficient way of doing it, but far easier than coding an in-place algorithm by hand).

  • shaieenshaieen Posts: 20Member
    hmmf... can u give me an example? coz.. i really don't know how to.. teennx..


    ~thanks
Sign In or Register to comment.