#include#include
#include <stdio.h>#include <stdlib.h>#include <math.h> int main (){int a=0;int b=0,n=0,s=0,t=0;scanf("%d,%d",&a,&n); while(n>=0){n--;a=a%(pow(10.0,n));b=a/(pow(10.0,n));s=s+b*(pow(10.0,t));}printf("%d",s); system("pause");return 0;}请问这里的问题是什么?怎么改?
首先,程序有一个最基础的错,在C/C++中,浮点不能用于取余的
a=a%(pow(10.0,n));
这个肯定是错的
其次,不清楚你程序的目的,你的算法也完全不对
1。你的s=s+b*(pow(10.0,t));没有意义,因为t==0
2。当n==0时,n--后,n为-1,
pow(10.0, n)取整后为0
你不可能取0的余数的
你若要对一个整形进行取其中的位数,肯定不要用到pow的,它用的是浮点,效率低,你有时不能用传统的数学方法解决计算机问题的
热门标签: