C++ program to display all even numbers from n1 to n2 using n2 as default argument

#include <iostream>
using namespace std;
void even(int n1,int n2=100)
{
    while(n1<=n2)
    {
        if(n1%2==0)
            cout<<n1<<" ";
        n1++;
    }
}
int main()
{
    even(6); //n1=6 and n2=100 as default argument
    return 0;
}

No comments:

Post a Comment