Home  >  Article  >  Backend Development  >  How to express numbers in tens of thousands in C language

How to express numbers in tens of thousands in C language

下次还敢
下次还敢Original
2024-05-02 18:12:311020browse

In C language, division and remainder operators are required to represent numbers in the tens of thousands place: 1. Divide by 10,000 to get the number in the tens of thousands place, and discard the remaining numbers. 2. Take the remainder 10 from the result to get the number in the tens of thousands place, discarding the higher order numbers.

How to express numbers in tens of thousands in C language

How to express numbers in the tens of thousands place

In C language, to express numbers in the tens of thousands place, You need to use the remainder operator (%) and the division operator (/).

Steps:

  1. Divide the number by 10,000: This will give you the number in the 10,000s place where any remaining digits are will be discarded.
  2. Round the result by 10: This will get the number in the tens of thousands place, discarding any higher digits.

Example:

To get the tens-thousands digit of the number 54,321, you can use the following code:

<code class="c">int num = 54321;
int thousands_digit = (num / 10000) % 10;
printf("万位上的数字:%d\n", thousands_digit);</code>

Output:

<code>万位上的数字:5</code>

Note:

  • If the number is less than 10,000, there will be no number in the tens of thousands place and its value will be taken in the thousands place.
  • To ensure that you always get a number in the tens of thousands place (even if it is 0), you can perform absolute value processing on the number before taking the remainder: abs(num / 10000) % 10.

The above is the detailed content of How to express numbers in tens of thousands in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn