1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Perfect Square - Prove the Computation Time Estimate

Discussion in 'C++' started by fmmctg0001, Sep 9, 2012.

  1. fmmctg0001

    fmmctg0001 New Member

    Joined:
    Sep 6, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    my prof was asking me to write a program to find and print the first perfect square (i*i) whose last two digits are both odd.
    my answer was this which completely wrong. please any one can help me to fix this program.
    And please explain in theory, any program that you write to solve the above problem will
    run for infinite time.
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int num = 0;
        int oddnum = 0;
        
        cout<<"Enter a number: ";
        cin >> num;
        
        while((num > 0) && (oddnum < 2))
        {
            int oddnum = num % 100;
            num/=100;
            
            cout<<endl<<"odd number"<<oddnum;
            if(oddnum %2 ==0)
            {
                
                cout<<" is even"<<endl;
            }
            else
            {
                cout<<" is odd"<<endl;
            }
            
        }
        
        return 0;
    }
     
    Last edited by a moderator: Sep 9, 2012

Share This Page