Answer to Question #265783 in C++ for Ninja

Question #265783

Write program that implements a function with the following header to display all

the even digits in an integer:

void displayEven(int number)

For example, displayEven(345) displays 4. Write a test program that prompts the

user to enter an 

integer and displays the even digits in it. Using User define functions


Sample output:

Enter an integer: 123456789

8 6 4 2



1
Expert's answer
2021-11-14T09:21:57-0500
#include <iostream>


using namespace std;


    int displayEven(int n){
        int r;
       while (n>0){
        r=n%10;
        n=n/10;
        if (r%2==0)
            cout<<r<<" ";
       }
};
int main()
{
    int n;
    cout<<"Enter a number "<<endl;
    cin>>n;
    cout<<"Even Numbers"<<displayEven(n);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS