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