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



Loop counting odd and even numbers

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-10-2009
Member
 
Join Date: Mar 2008
Posts: 672
Loop counting odd and even numbers
  

I want a way (a code in c or c ++) to display the result of given number,The best way to see if a given number is odd or even. Any recommendations and suggestions are appreciated.

Reply With Quote
  #2  
Old 23-10-2009
Member
 
Join Date: May 2008
Posts: 2,290
Re: Loop counting odd and even numbers

Code:
int main()
{
int in, evn=0, od=0;
do
{
cout << "Please enter a number:"<< ' ';
cin>> input;
if ( (evn%2 == 0) && (in >= 0) )
  even++;
else if (in >= 0)
  od++;
}
while (in>=0);
 
cout << "You have entered" << ' '<< od << ' ' <<"odd numbers." << endl;
cout << "And" << ' ' << evn << ' ' <<"even numbers." << endl;
system("PAUSE");
return 0;
}
Reply With Quote
  #3  
Old 23-10-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: Loop counting odd and even numbers

Code:
long oddno =1;
 long maxno;
 unsigned long lproduct;
 cout<<"enter the odd number";
 cin >> maxno;
 while( oddno<= maxno )
 {
       long tempno = oddno + 2;
       lpro = tempno *oddno;
       cout<<"the product of two numbers first number"<<oddno<<"second number"<<tempno<<"equals"<<lpro<<"\n";
       oddno = tempno;
}
Reply With Quote
  #4  
Old 23-10-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: Loop counting odd and even numbers

Use the AND operation.
Code:
for(int i=0;i<=100;i++)
{
if(i&1)
{
printf("Odd\n");
}
else
{
printf("Even\n");
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Loop counting odd and even numbers"
Thread Thread Starter Forum Replies Last Post
How to change negative numbers to positive numbers in Excel Shaina Na Microsoft Project 3 08-01-2012 04:35 PM
Need C program code to count numbers of negative & positive numbers Sarfaraj Khan Software Development 5 16-01-2010 01:00 PM
How to check Bingo game numbers in loop Afznotermi Software Development 3 29-10-2009 02:19 PM
Help with sh script loop counting Brake Fail Software Development 3 10-01-2009 05:48 PM
Counting numbers and deleting array SalVatore Software Development 2 25-08-2008 01:48 PM


All times are GMT +5.5. The time now is 02:16 AM.