Programming Shortcut

Write, Run and execute Your programs with simple and esay way by Programming Shortcut

Monday, February 4, 2019

List of even and odd numbers list 1 to n in c++

Hello friends! Welcome to my website

Today We Run a program to print all even and odd numbers lists in oops concepts in c++.
This session is how to print the even or odd numbers list in c++ Programming. Here we show you, how to use while loop and if loop programming with Example and oops concepts in c++
This c++ language programming is free all type of errors like the compiler and runtime errors and this programming is tested to compile and then run the program code.
Here is only programming code with the output. This programming output is customized to understand easily.


Print all even numbers between 1 to n in c++

#include <iostream>
#include <cmath>
using namespace std;
class test1 {
public:
int n;
void printeven(int n) {
int i =0;
while ( i< n) {
if(i%2==0){
cout<<i<<", ";
}
i++;
}
}
};
int main() {
test1 o ;
cout<<"Enter a Number till want list:"<<endl;
cin>>o.n;
cout<<"All Even Number list"<<endl;
o.printeven(o.n);
}


Output:    Enter a Number till want list: 20
All Even Number list
0, 2, 4, 6, 8, 10, 12, 14, 16, 18,


Print all odd numbers between 1 to n in c++

#include <iostream>
#include <cmath>
using namespace std;
class test1 {
public:
int n;
void printeven(int n) {
int i =0;
while ( i< n) {
if(i%2==1){
cout<<i<<", ";
}
i++;
}
}
};
int main() {

test1 o ;
cout<<"Enter a Number till want list:"<<endl;
cin>>o.n;
cout<<"All Even Number list"<<endl;
o.printeven(o.n);
}


Output:    Enter a Number till want list: 20
All Odd Number list
1, 3, 5, 7, 9, 11, 13, 15, 17, 19,

I make this programming and hope you are like the post if are you like the post you can please comment and Share the post to reach more people.
If any doubt about this c++ programming code or input & output please comment below
If you have another question about c++ programming send an email by contacting us form is given on the page right side.
I am Try to Help in your Programming Language by Programming Shortcut

Please share your experience about this post,
Thank You!

About Programming Shortcut

This is a programming learning website that can help you learn and when your write your programming code. And all programming code is compiled run programming code in the following programming language C, c++, Java, php and Javascript Languages. find your programming read, understand the programming then copy and past and run your program and save your golden time to typing the program becuse you learn more in leas time. All Programming is codeing is ease to understand the programming