1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

C puzzle

Discussion in 'C' started by vignesh1988i, Oct 6, 2009.

  1. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    how will you check the relation of two numbers (greater or lesser) without using Relational operators ?????? :D:D:D:nice::nice:
     
  2. manishgupta88

    manishgupta88 New Member

    Joined:
    Oct 5, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    By comparing them using IF Else
     
  3. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    for comparing u need relational operator na :):):) , use if-else.. but the question is without relational operators how will u decide the relation between two numbers....? please
     
  4. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    You can do it using the following logic:

    Let us assume the numbers to be x and y.

    Code:
    if(x/y)
        printf("x is greater");
    else
        printf("y is greater");
    
    Logic:
    If you divide a smaller number by a greater number the result will be "zero".

    case 1: x<y
    (x/y) results "0", in turn makes the condition if(o) => if(false) and so the else part is executed.

    case 2:x>y
    (x/y) results some positive value, in turn makes the condition to if(true) and so if part is executed.
     
  5. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    hmm.. it's correct:) good...... but take the worst case , take 'x' and 'y' to be same......... so let us assume x=90 , y=90 , is 90>90 or 90<90 , this statement is false..... so in ur logic , the ur if() will be true for u....... actually it mustt be false.........

    and my question is for alll operators , and not only fot > & < , also for >= , <= and ==..... and i ll say a clue , in all relational operators only one thing will change entirely, by changing that u can write the logic and check it......

    thank u
     
  6. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    oh... Can you reveal the solution that you expected?
     
  7. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    just u try it sir..... it's simple..... :):):):):)
     
  8. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    If the two numbers are same, we can find that out using this XOR condition:

    Code:
    if(x^y)
      printf("Both not equal");
    else
      printf("Both equal");
    
    Logic:
    If x and y are equal, then condition becomes if(0).
     
  9. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    HM-MM... for equality this is correct , for lesser or greater wat will be the logic.... :) :) :nice:
     
  10. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    I have already posted the result for lesser or greater :D
     
  11. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    ok you have posted , but i need it in a single condition .....:D.... using a single condition we can check for all numbers....... (>=,<=,>,<)

    that's i need....
     

Share This Page