ページ 11

よろしくお願いします。

Posted: 2008年2月03日(日) 21:31
by ねこ
下のwhile文のところをfor文かif文に変えますか?教えてください。
#include <stdio.h>

main()
{
int k, n;

printf("2以上の自然数を入力しなさい: ");
scanf("%d", &n);

printf("%d = ", n);
k= 2;
while (k < n) {
if (n%k == 0) {
printf("%d*", k);
n = n/k;
} else {
k++;
}
}
printf("%d\n", k);

return 0;
}

Re:よろしくお願いします。

Posted: 2008年2月03日(日) 21:33
by
>下のwhile文のところをfor文かif文に変えますか?

????

<pre>を使用してください。

ifとは、forとはどんなものでしたか?

返事ありがとうございます。

Posted: 2008年2月03日(日) 21:52
by ねこ
while文は私が勉強したことないので、その代わりに、for文又はif文ができるかなぁと思ってますが・・・

Re:返事ありがとうございます。

Posted: 2008年2月03日(日) 21:57
by
googleで検索するといい説明が多く出てくると思います。

int i=0;
while(i<10){
i++;
}

int i;
for(i=0; i<10; i++)

同じ意味になるはずです。
速度が変わったりするのかもしれませんが知りません。

雷さんへ

Posted: 2008年2月03日(日) 22:12
by ねこ
ありがとうございました。できました。