Interview Question

Software Engineer Interview(Student Candidate) Richmond, VA

see above

Answer

Interview Answer

1 Answer

0

Question: If I gave you 0-100 inputs, print X if even, Y if div by 5, the number if anything else.

Answer (there is probably a more elegant way to do this):

int main()
{
    int upperBound = 101;

        for(int i = 0; i < upperBound; ++i)
        {

            if(i % 2 == 0)
            {
                if(i % 5 == 0)
                {
                    cout << "Y ";
                }

                else
                {
                    cout << "X ";
                }
            }

            else
            {
                cout << i << " ";
            }

        }

    return 0;
}

Anonymous on May 7, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.