Find the maximum of two digits without judging the statement

Source: Internet
Author: User

#include "iostream.h"
#include "math.h"

#define BITS (sizeof (int) * 8-1)
static int Checkflag (int x, int y)
{
int S1 = x >> bits;
int s2 = y >> bits;
S1=abs (S1);
S2=abs (S2);
Return (S1 * 2 + s2);
}
static int samesign (int Flag, int x, int y)
{
int t[2] = {x, y};
Long z = x-y;
int s = z >> (bits+32);
S=abs (s);
return T[s];
}
static int diffsign (int flag,int x,int y) comparison
{
int t[2] = {x, y};
return t[flag-1];
}
static int (*funclist[4]) (int flag,int x,int y) ={samesign, diffsign, Diffsign, samesign};
static int Max (int x, int y)
{
int Flag = Checkflag (x, y);

Return (*funclist[flag]) (flag,x,y);
}
void Main ()
{
int x,y,z;
cout<< "Please enter the value of Integer x ( -32768~32767):";
cin>>x;
cout<< "Please enter the value of the integer Y ( -32768~32767):";
cin>>y;
Z=max (X,y);
cout<< "The largest number:" <<z<<endl;
}

#define BITS (sizeof (int) * 8-1)//number of digits moved

static int samesign (int Flag, int x, int y)//Function function: Comparison of x,y with same number

static int diffsign (int flag,int x,int y)//Function function: Comparison of x,y of different numbers

static int (*funclist[4]) (int flag,int x,int y) ={samesign, diffsign, Diffsign, samesign}; To define an array of function pointers

static int Max (int x, int y)//function function: Find the maximum value

static int Checkflag (int x, int y)//function function: detecting x,y symbols

/*
Flag 的值
+ +:0
- +;1
+ 1:2
- -:3
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.