0
好的,所以我的任務是從自然數中得到一個數字,然後求平方數(使用函數while,這意味着沒有數組:S)。例如,我輸入123,所以sum = 1 * 100 + 2 * 10 + 3 * 1;然而,問題在於數字可能是什麼。我的問題是,功率上升與整數,但它的像 - 1,10,99,1000。我的問題是99.也答案是循環,但我會稍後修復它。這裏是我的代碼:power int number while in loop
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int N,
number=0,
answer=0,
a=1,
i=0;
printf("Type natural number: ");
scanf("%d",&N);
while(N>i)
{
number=N%10;
N/=10;
a=10;
a=pow(a,i);
answer+=number*number*a;
printf("%d\n", answer);
i++;
}
return 0;
}
已經圍繞它與圓功能:)。不過謝謝你的建議。 – user240179 2014-10-11 13:23:53