# Thread: Program to print odd and even numbers

1. Member
Join Date
Nov 2009
Posts
53

## Program to print odd and even numbers

Hi All,

I am beginner in the field of the programming. That why my programming logic is little-bit weak. I need you help to write the program which will display the odd as well as even numbers from the given number range.

Is anybody able to provide me the program coding to check even & odd numbers.

I will appreciate your help..

2. Member
Join Date
May 2008
Posts
2,302

## Re: Program to print odd and even numbers

Hi

below are the code which I used to find out the even and odd numbers from the given number range:

#include<conio.h>
#include<stdio.h>

void main()
{
int p[12],q[12],r[12],x,y=0,z=0;
clrscr();
printf("Enter 12 numbers\n");
for(x=0;x<12;x++)
{
scanf("%d",&a[x]);
}
for(x=0;x<12;x++)
{
if((p[x]%2)==0)
{
b[y]=p[x];
j++;
}
else
{
c[k]=p[x];
kz+;
}
}
printf("even numbers =");
for(x=0;x<y;x++)
{
printf("%d\n",q[x]);
}
printf("odd numbers =");
for(x=0;x<z;x++)
{
printf("%d\n",r[y]);
}
getch();

}
Please try to run this program

3. Member
Join Date
Oct 2005
Posts
2,394

## Re: Program to print odd and even numbers

Hi,

I don't have knowledge about c and C++ language . So I am providing you the in the java language . Please copy this program on your machine ,and run the program. The output of the program will give you the even and odd numbers:

import java.util.*;

public class EvenOddNum
{
public static void main(String[] args)

{
int a;

char choice1;
Scanner cs = new Scanner(System.in);

do
{

a = cs.nextInt();

if(a%2 == 0; a++)
{
System.out.println("Even number =" + a);
}
else
{
System.out.println("Odd number =:" + a);
}

System.out.println("Do you like to try another number? :");
choice1 = cs.next() .charAt(0);

}while (choice1 == 'y' || choice1 == 'Y');
}
}

4. Member
Join Date
May 2008
Posts
2,393

## Re: Program to print odd and even numbers

Hi friends,

See something below can help you to code the program for odd and even numbers between 1-20. I have used the same JAVA program and it's running:

public static void main(String[] agrs) {

int cnt = 0;

do {

cnt++;

if (cnt % 2 == 0) {

System.out.println(cnt + "given number is even");
}
else {

System.out.println(cnt + "given number is odd");

}
}
while(cnt != 20);

}
}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•