” Find sequence number with C + + “

how to find the number of odd and even numbers, and the total of the odd and even numbers?

before that we must classify odd and even numbers

– Even
number of even number
number of even number

– Odd
The number of odd numbers
the number of odd numbers

 

 

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

void main(){
int n,a,b,x,y,i ;
cout << “Input N : ” ; cin >> n ;
a=0 ; b=0 ; x=0 ; y=0 ;

for (i=1 ; i <= n ; i++){
if (i%2==0) {
a = a+i ; x = x+1 ;
}
else {
b = b+i ; y = y+1 ;

}
}

cout << “\n Number of even number:  ” << x;
cout << “\n Number of odd numbers : ” << y;
cout << “\n Number of even numbers : ” << a ;
cout << “\n Number of odd numbers : ” << b ;
getch () ;
}

 

Good Luck Friend

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: