C++ problems plz plz help me friends

Discussion in 'C++' started by Nav, Mar 21, 2010.

  1. Nav

    Nav New Member

    Joined:
    Mar 21, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Plz solve this 3 programs for me if possible.i m not able to get coding .
    1. bool inside= !((x<left)||(x>right)||(y<top)|| (y>bottom));

    2. bool no =
    (ch[0])=='N'&& ch[1]=='0')||
    (ch[0])=='n'&& ch[1]=='0')||
    (ch[0])=='N'&& ch[1]=='0')||
    (ch[0])=='n'&& ch[1]=='0');

    3. given 1+3+....(2p-1)=p(square) for any integer p>=1. here i need a function which find out whether a given number is a perfect square. here i cant use array, nested looops, math functions and arithmetic operations except addition.



    Plz Plz help me guys i really great full to u. :nonod:
    thanx for giving me ur precious time.:lipsrseal
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I don't understand the problem with 1 and 2 and "i'm not able to get coding" - you already have coding. Are you trying to understand what the code does? Both seem pretty obvious though from the naming: could it be that "inside" tells you if x and y are inside something?

    3. OK, this isn't difficult. Have you thought how you might do it? Do you think a for statement might be useful? If so what would the three expressions within the for statement be? What do you think might need to happen within the loop?

    Here's a possible algorithm: start with 1 and compare it with the number under test. What do you think "less than", "equal" and "greater than" would imply? If you haven't found a result, go onto the next square (4, found by adding 3). Compare with the number under test again. If you decide continue, add 5 to get to the next square (9), and repeat. Repeat until what? If the current square is less than the number under test you know what to do (continue looping), if they're equal then you've found that the number under test is a square, so would the repeat continue until something is greater than something?

    Pretty much written it for you there. Have a go at writing the code and see how far you get. Think carefully about the code. When you're stuck, try to solve the problem yourself and only post the code here if you're really stuck.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice