求指教!为什么这个程序vc可以输出结果在Dev-cpp运行到scanf那里就不走了

明朝一典史 2014-08-13 09:34:37
#include<stdio.h>
#include<math.h>
int main()
{
unsigned int a=0;
printf("Enter a postive integer: ");
scanf("%d",&a);


int i=1,
j=1,
n=0,
sum=0,
c=a,
b=0;
do
{
n=pow(10,i);
b=(c%n)/(n/10);
c-=b*(n/10);
i++;
}
while(c!=0);

c=a;
do
{
n=pow(10,j);
b=(c%n)/(n/10);
c-=b*(n/10);
sum+=b*pow(10,i-2);
j++;
i--;
}
while(i>=0);
printf("The number %d reserved is %d rebmun ehT.",a,sum);
return 0;







}

编译器为vc++6。0
Dev-c++5.4.1
...全文
319 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-08-14
  • 打赏
  • 举报
回复
pow Calculates x raised to the power of y. double pow( double x, double y ); Routine Required Header Compatibility pow <math.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value pow returns the value of xy. No error message is printed on overflow or underflow. Values of x and y Return Value of pow x < > 0 and y = 0.0 1 x = 0.0 and y = 0.0 1 x = 0.0 and y < 0 INF Parameters x Base y Exponent Remarks The pow function computes x raised to the power of y. pow does not recognize integral floating-point values greater than 264, such as 1.0E100. Example /* POW.C * */ #include <math.h> #include <stdio.h> void main( void ) { double x = 2.0, y = 3.0, z; z = pow( x, y ); printf( "%.1f to the power of %.1f is %.1f\n", x, y, z ); } Output 2.0 to the power of 3.0 is 8.0 Floating-Point Support Routines See Also exp, log, sqrt http://bbs.csdn.net/topics/390676437
明朝一典史 2014-08-14
  • 打赏
  • 举报
回复
引用 13 楼 brookmill 的回复:
我觉得可能是unsigned int和%d不匹配造成的问题。楼主可以试试这两个改动: 1. unsigned int a=0; scanf("%u",&a); 2. int a=0; scanf("%d",&a); 一般情况下unsigned int和%d混用都问题不大,dev-cpp不知道有什么不一样。 顺便说一句,我刚入行的时候曾经这么干过: short a; scanf("%d", &a); 结果就把栈弄崩了,自己还不知道是怎么回事。从那以后就觉得scanf太危险了(其实该说指针太危险了)
非常感谢 不过我试过了不是这个原因 原因是就是上面所说的 还是很感谢
明朝一典史 2014-08-14
  • 打赏
  • 举报
回复
引用 14 楼 zhao4zhong1 的回复:
pow Calculates x raised to the power of y. double pow( double x, double y ); Routine Required Header Compatibility pow <math.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction. Libraries LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return Value pow returns the value of xy. No error message is printed on overflow or underflow. Values of x and y Return Value of pow x < > 0 and y = 0.0 1 x = 0.0 and y = 0.0 1 x = 0.0 and y < 0 INF Parameters x Base y Exponent Remarks The pow function computes x raised to the power of y. pow does not recognize integral floating-point values greater than 264, such as 1.0E100. Example /* POW.C * */ #include <math.h> #include <stdio.h> void main( void ) { double x = 2.0, y = 3.0, z; z = pow( x, y ); printf( "%.1f to the power of %.1f is %.1f\n", x, y, z ); } Output 2.0 to the power of 3.0 is 8.0 Floating-Point Support Routines See Also exp, log, sqrt http://bbs.csdn.net/topics/390676437
非常感谢!! 我看了Dev有关math.h里面有关pow的定义发现pow的参数必须是float 或者 long double型 如下: /* 7.12.7.4 The pow functions. Double in C89 */ extern float __cdecl powf (float, float); #ifndef __NO_INLINE__ __CRT_INLINE float __cdecl powf (float x, float y) {return (float) pow (x, y);} #endif extern long double __cdecl powl (long double, long double); 改过来就好了
brookmill 2014-08-14
  • 打赏
  • 举报
回复
我觉得可能是unsigned int和%d不匹配造成的问题。楼主可以试试这两个改动: 1. unsigned int a=0; scanf("%u",&a); 2. int a=0; scanf("%d",&a); 一般情况下unsigned int和%d混用都问题不大,dev-cpp不知道有什么不一样。 顺便说一句,我刚入行的时候曾经这么干过: short a; scanf("%d", &a); 结果就把栈弄崩了,自己还不知道是怎么回事。从那以后就觉得scanf太危险了(其实该说指针太危险了)
百曉生 2014-08-13
  • 打赏
  • 举报
回复
gcc下执行的确没问题
我的C-Free执行的确出不来结果,我单步时发现n在i等于2时变成了99而不是100,不知道是不是编译器问题——
楼主不妨单步一下VC6和dev试试,看看有什么不同
明朝一典史 2014-08-13
  • 打赏
  • 举报
回复
引用 10 楼 T5500 的回复:
汗,没看仔细你的问题,帮不上忙了
还是很感谢!
乌镇程序员 2014-08-13
  • 打赏
  • 举报
回复
汗,没看仔细你的问题,帮不上忙了
明朝一典史 2014-08-13
  • 打赏
  • 举报
回复
好吧。。。 我去看看Dev和其他编译器有什么不同
乌镇程序员 2014-08-13
  • 打赏
  • 举报
回复
gcc 4.9.0
明朝一典史 2014-08-13
  • 打赏
  • 举报
回复
引用 5 楼 T5500 的回复:
执行没问题啊
哦?兄弟你用的也是Dev吗?
明朝一典史 2014-08-13
  • 打赏
  • 举报
回复
[img=https://img-bbs.csdn.net/upload/201408/13/1407938524_155258.png][/img
在vc里就是这样可以出来
在Dev里就蛋疼了。。。。
不知道怎么弄了
乌镇程序员 2014-08-13
  • 打赏
  • 举报
回复

执行没问题啊
神奕(deprecated) 2014-08-13
  • 打赏
  • 举报
回复
是不是死循环了??
明朝一典史 2014-08-13
  • 打赏
  • 举报
回复

走到这就不走了
乌镇程序员 2014-08-13
  • 打赏
  • 举报
回复
正在等你输入一个正整数

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧