//数字翻转 #include<stdio.h> int main(){ unsigned int number = 0; unsigned int rebmun = 0; unsigned int temp = 0; //read the value to be reversed printf("\nEnter a positive integer"); scanf("%u", &number); temp = number; //reverse the number stored int temp do{ rebmun = 10*rebmun + temp % 10;//add rightmost digit of temp to rebum,执行一次迭代时把个位数字挪到前面 //一个一个的把最后面的数字往前面提,23,变成32. temp = temp / 10; //remove it from temp }while(temp); printf("\nThe number %u is reversed is %u rebum\n", number, rebmun); return 0; }
ps:
digits & number:
Number、Numeral 、Digit和Figure
Number、numeral、digit和figure都和数字有关,有的人把它们当作同义词来用,但事实上它们含义并不一样。那么具体区别是什么呢?
Number是个抽象的数量概念(idea),看不见摸不着。其表达形式(token/sign/symbol/name/mark/figure)用来计数(counting)和测量(measurement),则可以看得到。通常用numeral来表达number,当然还可以用手势、声音等其它方式。
Numeral是代表(represent)数量概念的符号,有不同的书写体系(writing system),例如罗马数字(Roman numerals)【numeral XVII代表17】和印度阿拉伯数字(Hind-Arabic numerals)【即阿拉伯数字】。简单说,numeral就是把number写出来的方法。例如,三的抽象数量概念(threeness)可以具体表达为‘three’、‘3’、‘III’、‘11’【二进制(binary)】、‘三’和其它形式。Numeral广义上指任何代表数字的符号,但狭义上就指阿拉伯数字。
Digit是用来表达numeral的单独符号(single symbol)。日常生活中用0、1、2、3、4、5、6、7、8与9十个digit来表达number。例如,numeral 153由三个digit【1、5和3】来组成;numeral 9由一个digit【9】组成。
所以,digit组成numeral,而numeral代表number。可以用单词和字母来打比方。Letter组成word,而word代表idea。例如,dog有三个字母【d、o和g】组成,而dog表达‘狗’的概念。也可以用人和名字打比方,number类似一个人,而numeral则是他的名字;名字并不是人,但代表那个人。一个人可能有几个名字【学名、小名、外号、英文名】,但都指同一个人。
严格地讲,特指数字符号时用numeral或figure;特指单个数字时用digit;其它情况则用number。日常用语无须如此计较number和numeral的区别,通常可以用number来代替numeral。
Number 在日常使用中既可指文字形式也可指数字形式的数量概念,所以如果强调文字形式用spell out或word;反之则用figure、digit或numeral。而write out则似乎两者皆可。例如:
l The small numbers, such as whole numbers smaller than ten, should be spelled out.
l Some experts say that any one-word number should be written out.
l Two-word numbers should be expressed in figures.
l With everyday writing and recipes you can use digits, like “4% of the children” or “Add 2 cups of brown rice.”
l You should use numerals, not words, when the number is a key value, an exact measurement value, or both. For example, in the sentence “Our computer backup system uses 4 mm tape” the numeral is in order.
l Rounded numbers over a million are written as a numeral plus a word. Use “About 400 million people speak Spanish natively,” instead of “About 400,000,000 people speak Spanish natively.” If you’re using the exact number, you’dwrite it out, of course.【这里write out 应该指用数字表示准确数量,而非文字】