数値を数値に分割して、追加すると最初の数値を与えるプログラムを作成しました。たとえば、1234年は1000年、200、30に分割されなければならない、と4pow()関数を使用したときの不正確
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int i, num1, num2;
char tmp[6]; // the number will be stored here as string
int num3 = 12345; //the number
sprintf(tmp, "%d", num3); //convert to string
for(i = 0; i < strlen(tmp); i++) //check every digit
{
num1 = pow(10, strlen(tmp) - 1 - i); //every number will be multiplied by 10
//to the power of number of digits - 1 - counter
num2 = tmp[i] - '0'; //convert character to int
printf("%d\n", num1*num2); //print the number
}
return 0;
}
は、これが出力されます。
9999
2000
297
40
5
あなたはなぜ、これは、正しくない見ることができるように?
あなたの投稿のバージョンは 'pow'は、浮動小数点表現の誤りが含まれているためであるhttp://ideone.com/K3pY8r – xvan
として動作しているようです。 – BLUEPIXY
複数のオンラインコンパイラで試してみましたが動作しますが、私のPCでは動作しません。そのエラーを避けるにはどうすればよいですか? – user3711671