find largest of three numbers without using comparsion operator

Hello Friends.

I am not able to solve a question in C If u have any idea pls help me

The Question is

program to find largest of three numbers without using comparsion operator

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    Share your attempts at coding this program and tell us where exactly you're stuck.
  • arunslb123
    arunslb123
    ct=0;
    while(var1 && var2 && var3){
    var1++;
    var2++;
    var3++;
    ct--;
    }
    printf("%d",ct);

    could u pls explain this
  • Pensu
    Pensu
    @arunslb123: This is the beauty of programming, you can make it dance the way you want. The program you have given produces correct result. Lets start it with taking an example, suppose a(var1)=4, b(var2)=5, c(var3)=6 and u have already said ct=0. As u might know, that while loop runs till the condition is true and to stop it one of the variables has to be 0. So, when you start the execution the values of each variable starts increasing and ct starts to go in negative. Now our poor integer can take only 32768 values. So when each of the variable reaches 32768 it starts running in negative(whoa...๐Ÿ˜‰). And as you are doing incremental operation, and as the value -5 is greater than -6, all the variables start to run towards 0.

    NOw u can question, what d hell is ct doing?? Well, it is also in race, but it is running in opposite direction,coz u gave it the sign "--". It goes to negative side first and it will cover positive side. So, the race is on and we know that as soon as any of the variable becomes zero, the loop execution will stop. So, the big question is who wins the race, and you guessed it right, the variable with the biggest value. It started first, which is not fair though...๐Ÿ˜‰, but still he is the winner. As soon as any of the variable becomes zero loop stops and guess what the ct is now reached to the position of highest value variable. As they were running fairly, each of them having one step at a time. So, ct will stop at the highest value and print it.
  • arunslb123
    arunslb123
    thanks a lot bro......
  • diwana.nanda
    diwana.nanda
    i didnt get the logic of while loop cn sm1 explain plz
  • lovejeet
    lovejeet
    the logic of while loop is that it will execute till the arguement we put in becomes false.
    the false is represented by the value 0.
    so for ex,
    while ( x)
    {
    statements;
    x--;
    }
    this loop will execute till the value of x becomes 0.
  • diwana.nanda
    diwana.nanda
    no no i know the while loop logic,,i mean logic of coding in this program and can you plz write full program.
  • Pensu
    Pensu
    @diwana: I guess i wrote the whole logic already, u can read it again and if you any problem ask it specifically, i mean where exactly u have the problem. And its the whole program, u just need to add header files and yeah, braces too, and u might wanna declare the variables also before using them....๐Ÿ˜› , thats it, thats the whole program. And i see you have started another thread for the same program namely "question of programming in C". Well, you have the answer in this thread only....๐Ÿ˜€
  • simplycoder
    simplycoder
    *CROSS POSTER*
    #-Link-Snipped-#

You are reading an archived discussion.

Related Posts

Just wondering who all is going to be brave enough to install the Replicant OS on their smartphone! I don't have one yet, though I've been tempted to get one...
hello everyone!! I am a final year student of ECE and want to do a project using the applications of DSP and soft computing in wireless communication. please suggest and...
hello CEans ๐Ÿ˜€ there must be some CEans appearing for the CAT 2011 which starts today and extends till 18th november, 2011. the prometric is conducting the online test this...
Hello, I am currently in f y btech computer engineering. My dream is to get hired by top companies like Microsoft, Google and Facebook and work abroad. So during these...
I am referring to the topic, window design with Non-parametric spectrum estimation. Anybody has any idea, that what is actually point of maximum leakage in spectrum estimation? Thanks in advance.