-
#include
int main()
int n;
scanf("%d",&n);
while(n/10)n/=10;Divided by 10, a zero means that only the highest position remains.
printf("%d",n);
return 0;
-
Divide by 10 with a while loop until only the highest bit remains.
This brings you to the highest digit.
-
The number of single digits, ten factions and hundreds of digits can be output in C language respectively, according to the following steps, C language as a program**, so you must not make any mistakes in any symbols when entering. Edan chair.
#include
int main()
int x;
scanf("%d",&x);
printf("Hundred digits of %d = %d, ten digits = %d, single digits = %d",x,x/100,x/10%10,x%10);
return 0;
Expand the information of the envy exhibition#include
main()
int a;
printf("Please enter a three-digit number:")
scanf("%d",&a);
printf("Hundreds: %d",a/100);
printf("Tens of digits: %d",(a%100)/10);
printf("Hundreds: %d",a%10);
Encyclopedia c language.
-
#include
int main()
int num = 789;
int hundreds = num / 100;Get the hundred-digit number.
int tens = num / 10) %10;Get ten digits.
int ones = num % 10;Get a single digit.
printf("The hundredth digit is: %d", hundreds);
printf("The ten-digit number is: %d", tens);
printf("The single-digit ruined was: %d", ones);
return 0;
In the example above, we use the integer variable num to represent a three-digit royal medium. We use the integer variable hundreds to get the hundreds, (num 10) %10 to get the ten digits, and num % 10 to get the single digits. Finally, we use the printf() function to output each number to the screen separately.
-
If n is a multi-digit decimal number, then n%10 is a single digit, n 10%10 is a ten-digit number, n 100%10 is a hundred digit, and so on.
Let a number be n, then in C language, its single digit, ten digits, hundred digits, and thousand digits are calculated as follows: n 1% 10, n 10% 10, n 100% 10, n 1000% 10
**As follows: include
int main()
-
To output a three-digit (e.g., 123) single digit, ten cluster rise, hundred digit, you can use the properties of integers and the modulo operator % to calculate the liquid. Here's how:
c#include
int main()
int num = 123;
int ones_digit, tens_digit, hundreds_digit;
Count the numbers.
ones_digit = num % 10;
tens_digit = num / 10) %10;
hundreds_digit = num / 100) %10;
Output digits.
printf("Single digit: %d", ones_digit);
printf("Ten digits: %d", tens_digit);
printf("Hundreds: %d", hundreds_digit);
return 0;
In the above, a three-digit num is defined and initialized to 123. Next, use the modulo operator % and integer division to calculate num, and save the single, ten, and hundred digits of num to the ones digit, tens digit, and hundreds digit variables, respectively.
After the last punch, use the printf function to output the digits. Run the program and the output will look like this:
Single digits: 3
Ten digits: 2
Hundreds: 1
Four digits (e.g. 1234): Thousands = num 1000, Hundred digits = num 100) %10, Ten digits = num 10) %10, single digits = num % 10.
Five digits (e.g. 12345): 10,000 digits = num 10000, 100 digits = num 1000) %10, 100 digits = num 100) %10, 10 digits = num % 10, single digits = num % 10.
-
If you see, the highest digit is different, the highest digit is the sign bit 3: the unsigned integer range: 0000h ffffh (decimal is 0 65535), there is no negative number, and the highest digit is also a numeric value.
4: Because 0-1 in 16 digits is ffffh, and if in 8 digits it is ffh
-
The first problem: the symbol flag bit is, for example, the int type is a signed shape, accounting for two bytes, a total of 16 bits, the highest bit is the symbol flag bit, when the input -1 is put into the int type, the highest bit is 1, the 1 at this time is when the symbol flag bit is used, does not represent the numerical value, 1 means that the stored number is negative, 0 means that the number is negative.
The second problem: it is the highest bit of the data, not the highest bit of the data, such as 100000000000000000000, and the highest bit of this binary number is 1.
The third question: %d is the output in signed decimal, %u refers to the unsigned output, when the int type data is stored in the unsigned value range of 0-65535, when stored in the signed value range is -32768-32767, when stored in the unsigned number is the size of the value, not positive or negative, but when stored in signed it represents plus or minus.
The fourth problem: the data is stored in the form of complements in memory, which involves another problem, the complement of positive numbers is itself, and the complement of negative numbers is the inverse code of its absolute value +1, the absolute value of -1 is 1, 1 is 0000000000000001 in binary storage, its inverse code is 1111111111111110, and +1 is 1111111111111111, that is, 2 to the 16th power minus 1I hope you have solved your doubts.
-
The data inside the computer (in memory) is an untyped sequence of bytes, with each byte (8 bits) being 0 255.
In order to express a larger range of numbers, we understand two consecutive bytes (a total of 16 bits) as a number, so that the range can reach 0 65535;
In order to be able to represent negative numbers, there are rules on how to use 0 65535 to represent negative numbers.
At present, the representation of the complement is commonly used in calculations. In this method, the highest bit is the sign bit, with 0 being a positive number, 1 being a negative number, and the remaining 15 digits being a numeric value. The range that can be represented by 15 bits is 0 32767, and if it is a negative number, the absolute value is inverted by bit and then added to 1 as a complement.
Take -1 as an example, first invert 1 by digit, get 0xfffe, and then add 1 to 0xffff.
Let's talk about the issue of signed and unsigned.
int k=-1;The first is the int type, which means that it needs to occupy 2 bytes (int is 4 bytes on a 32-bit system), k = -1, and the value is 0xffff at the position of k (2 bytes).
Now, in this position, if you press the signed (i.e., int), the value is -1, and if you look at it unsigned, it is 65535
2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More
Operate from right to left, -i--so calculate -i first--, the operation level is higher, so it can be written as -(i--)i--for 8, add a - sign, so -i--is 8, at this time i--after, i=7, and then -i++ is the same, can be written as -(i++) so -i++ is -7, at this time i++ becomes 8,--i, subtract 1 before execution, so --i is 7, at this time i=7, ++i is the same, add 1 before executing i, so ++i is 8, at this time i=8, then calculate i--,i--is still equal to 8, then i minus one becomes 7, i++, i++ is equal to 7, and then i++, i=8, so finally i=8, and then print it out in turn, pay attention to the operation is from right to left, but print from left to right print i,i++,i--,i,--i,-i++,i-, so the check mark result is out.
The first if(!) a) means that if a is equal to zero, take x -- the second and third means that if b and c are not 0, it is executed. >>>More
C is process-oriented.
C++ is object-oriented. >>>More
This problem requires understanding that the system allocates memory to static variables when compiling, and the memory units occupied by them are not released after the function call ends, that is, the value of the variable is the value of the previous function call at the next function call. >>>More