Results 1 to 4 of 4

Thread: Program to print odd and even numbers

  1. #1
    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. #2
    Join Date
    May 2008
    Posts
    2,297

    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. #3
    Join Date
    Oct 2005
    Posts
    2,393

    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. #4
    Join Date
    May 2008
    Posts
    2,389

    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);

    }
    }

Similar Threads

  1. Program to print GCD of given numbers
    By Bhavesh_seth in forum Software Development
    Replies: 5
    Last Post: 15-03-2011, 08:03 PM
  2. C Program to print Combination of numbers
    By Prashobh Mallu in forum Software Development
    Replies: 6
    Last Post: 26-03-2010, 09:21 PM
  3. Need C program code to count numbers of negative & positive numbers
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 02:00 PM
  4. C sharp program to print random numbers
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:07 PM
  5. What is the program to swap two numbers?
    By Bharat89 in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 09:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,291,268.02829 seconds with 17 queries