Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,987 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,398 people online right now. Registration is fast and FREE... Join Now!




how to get maximum of three number using arithmatical operator only.

 
Reply to this topicStart new topic

how to get maximum of three number using arithmatical operator only., we can use +,-,*,/,MOD,sqrt etc

alokrj
29 Nov, 2006 - 04:38 AM
Post #1

New D.I.C Head
*

Joined: 29 Nov, 2006
Posts: 1


My Contributions
CODE

#include<iostream>
using namespcae std;
int main()
{
int max(int,int,int);
cout<<"enter 3 number";
int a,b,c;
cin>>a>>b>>c;
cout<<"Maximum number is"<<max(a,b,c);
}
int max(int a,int b,int c)
{
/*now wt will b the logic to get maximum among 3 number using aritmatical operator only, can any1 will help me to get the anser.*/
}


This post has been edited by Dark_Nexus: 29 Nov, 2006 - 02:14 PM
User is offlineProfile CardPM
+Quote Post

Xing
RE: How To Get Maximum Of Three Number Using Arithmatical Operator Only.
29 Nov, 2006 - 04:53 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 4 times
Dream Kudos: 1575
My Contributions
You can use this
CODE
int maxof2(int a,int b)
    {
        return (a + b + abs(a - b))/2;
    }

Before using the method make sure there's no underflow/overflow of integer value otherwise the code has undefined bahaviour.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 07:37PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month