Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Program to print odd and even numbers

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 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.

I will appreciate your help..

Reply With Quote
  #2  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,291
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<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
Reply With Quote
  #3  
Old 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');
}
}
Reply With Quote
  #4  
Old 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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Program to print odd and even numbers"
Thread Thread Starter Forum Replies Last Post
Program to print GCD of given numbers Bhavesh_seth Software Development 5 15-03-2011 08:03 PM
C Program to print Combination of numbers Prashobh Mallu Software Development 6 26-03-2010 09:21 PM
Need C program code to count numbers of negative & positive numbers Sarfaraj Khan Software Development 5 16-01-2010 01:00 PM
C sharp program to print random numbers Prashobh Mallu Software Development 5 12-01-2010 11:07 AM
What is the program to swap two numbers? Bharat89 Software Development 3 26-11-2009 08:37 AM


All times are GMT +5.5. The time now is 11:55 PM.