Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to define a hexadecimal number in C language
How to define a hexadecimal number in C language

Example:

int main(){

int a;

scanf("%p",&a);// To input a hexadecimal number %p is to enter a hexadecimal number scanf("%llx",&a); you can also enter hexadecimal and it is more formal

printf("%d", a);//Decimal output %d is to output a decimal number

printf("0x%x",a);//Hexadecimal output printf("%llX\n",a) ;You can also output a hexadecimal number. If the red part is a capital p>

The maximum number is 15 digits, which does not exceed the maximum number that can be expressed by __int64. __int64 can represent a maximum of 16 hexadecimal numbers. So just add and subtract directly. What you need to pay attention to is the input and output format and the two's complement code displayed when expressing negative numbers in hexadecimal.

#include<stdio.h>

int main(void)

{

long long a,b,result;< /p>

while(scanf("%llx%llx",&a,&b)!=EOF){

result=a+b;

if(result> =0)

printf("%llX\n",result);

else

printf("-%llX\n",-result) ;

}

return 0;

}

long long type format character:

Extended information:

Return usage:

The function is to end the running function and return the function value. return can be followed by a constant, variable, or expression.

The definition of a function is generally like this, for example:

int a (int i) //The first int is the type of the return value of the function, which is what follows return The type of value, a is the name of the function, the parameters in parentheses are the parameters passed to the function, int is the type of the parameter, i is the name of the parameter

{

.../ /Omit function body content

return b;//b must be consistent with the return value of the function header (here is int type)

}

Simple function Example:

int addOne(int b)

{

return b+1;

}

The function of this function is to get a number, add 1 to this number, and then return the result

When called, it looks like this:

int result=addOne(2); //At this time The value of result is 3

The parameters in the function brackets can also be variables or expressions that can calculate the value

The above is a basic function, and general functions have return values. That is, the value followed by return. The return value can be various data types, such as: int, float, double, char, a[] (array), *a (pointer), structure or class (c++)

But not all functions have a return value. If a function has no return value, the position of the return value is the "void" keyword. At this time, there is no return value in the function body, that is, there is no return value.

However, return can also appear in a function, that is, an empty return sentence. Its function is to end the function immediately, such as

void print () // Empty in brackets means no parameters are passed

< p>{

printf("a");

printf("b");

return;//The function execution ends here

p>

printf("c");

}//This function is only executed to the return statement, that is, the output on the screen is "ab"