How do I print an even number from C++ for loop?
How can I print an even number program from C++ Using For loop?
- C++ is a general-purpose programming language.
- C++ is a cross-platform language that can be used to create high-performance applications.
- It was developed by Bjarne Stroustrup.
- #include<iostream>
- using namespace std;
- int main()
- {
- int i , num;
- cout<<”Enter a number:\n”;
- cin>>num;
- for(i=1; i<mum; i++)
- {
- if(i%2==0)
- {
- cout<< i << “ ” ;
- }
- }
- return 0;
- }
The output of the following code is:
Enter a number:
10
expected output: 2 4 6 8
Comments
Post a Comment