[問題] 反轉數字
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
希望得到的正確結果:
EX:123
VC++:321
Dev-C++:320
程式跑出來的錯誤結果:
VC++跑出結果正確,Dev-C++結果錯誤
C++ or gcc/g++ or Dev-C++, Windows or Linux)
VC++ && Dev-C++
有問題的code: (請善用置底文標色功能)
#include<stdio.h>
#include<math.h>
unsigned int rev(unsigned int x);
int total,count,temp[50];
unsigned int num[100],result;
int main()
{
result=rev(123);
printf("%d\n",result);
return 0;
}
unsigned int rev(unsigned int x)
{
int n;
unsigned int y=0;
for(count=0;x>10;count++)
{
temp[count]=x%10;
x/=10;
}
temp[count]=x;
for(n=0;n<=count;n++)
y+=temp[n]*pow(10,count-n);
return y;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.197.86
推
09/16 23:48, , 1F
09/16 23:48, 1F
推
09/16 23:49, , 2F
09/16 23:49, 2F
→
09/16 23:53, , 3F
09/16 23:53, 3F
→
09/17 00:09, , 4F
09/17 00:09, 4F
→
09/17 00:10, , 5F
09/17 00:10, 5F
→
09/17 00:10, , 6F
09/17 00:10, 6F
→
09/17 00:11, , 7F
09/17 00:11, 7F
→
09/17 00:13, , 8F
09/17 00:13, 8F
→
09/17 00:13, , 9F
09/17 00:13, 9F
→
09/17 00:13, , 10F
09/17 00:13, 10F
→
09/17 00:21, , 11F
09/17 00:21, 11F
→
09/17 00:37, , 12F
09/17 00:37, 12F
→
09/17 01:19, , 13F
09/17 01:19, 13F
→
09/17 01:27, , 14F
09/17 01:27, 14F
→
09/17 07:27, , 15F
09/17 07:27, 15F