TechArena Community Program to print odd and even numbers

#1
30-11-2009
 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.

#2
30-11-2009
 Member Join Date: May 2008 Posts: 2,293
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:

Quote:
 #include #include 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
Please try to run this program
#3
30-11-2009
 Member Join Date: Oct 2005 Posts: 2,389
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:

Quote:
 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
30-11-2009
 Member Join Date: May 2008 Posts: 2,383
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:

Quote:
 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); } }
__________________
The FIFA Manager 2009 PC Game