## Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only

program help: array sort odd & even numbers Posted by shaieen on 21 Feb 2009 at 5:22 PM
i ran the program but it have errors. kindly check them huh? thanks!!
and..

please add codes for this to the program:

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

#include<stdio.h>
#include<conio.h>
void main(){

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

printf("Enter 10 positive numbers: \n");
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: \n");
for (i=0;i<j-1;j++)}
printf("%d\n",b[i]);
}
printf("The odd numbers are: \n");
for(i=0;i<k-1;i++){
printf("%d\n",c[i]);}
getch();

}
Re: array: grouping the input into odd, and even Posted by Malcolm_McLean on 22 Feb 2009 at 9:17 AM
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).

Re: array: grouping the input into odd, and even Posted by shaieen on 22 Feb 2009 at 7:03 PM
hmmf... can u give me an example? coz.. i really don't know how to.. teennx..

~thanks Ö

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.