![]() |
發(fā)布時間: 2018-12-12 09:53
正文摘要:單片機中,C語怎樣把數(shù)倒過來,比如一組數(shù)為12345,我要把她反來,即變成54321這樣。 要怎樣編寫?謝謝!!! |
張海見 發(fā)表于 2018-12-12 10:46 明天試試,謝謝! |
wulin 發(fā)表于 2018-12-12 11:31 這種方法不錯,明天寫一個出來。 |
本帖最后由 吳語吖 于 2018-12-12 13:13 編輯 我是個新手,只會最傻的辦法, unsigned int temp temp=shuzhu[4] shuzhu[4]=shuzhu[0] shuzhu[0]=temp; ...... 這樣, |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
本帖最后由 wulin 于 2018-12-12 13:09 編輯 unsigned int table[5]; unsigned int a=12345; unsigned int b=0; unsigned char i; table[0]=a/10000%10; table[1]=a/1000%10; table[2]=a/100%10; table[3]=a/10%10; table[4]=a%10; for(i=4;i>0;i--) table[4]=table[4]*10+table[i-1]; b=table[4]; |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
直接用個中間變量,a[2]=temp;a[2]=a[1];a[1]=temp;加個for循環(huán)應該可以 |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
定義數(shù)組,然后利用for循環(huán)過來改變。 int a=[1,2,3,4]; int b=[]; int i=0; for(i<4;i++) b(i)=a(3-i); |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
Powered by 單片機教程網(wǎng)