0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[質問] C言語 1〜100の中から素数を判定し、それらを表示するプログラムについて

Posted at

if文やwhile文を最近習った、プログラミング初心者です。
「1から100まで、素数かそうでないかを判断し、表示するプログラム」
これをwhile文を用いて作成せよ、という課題が出ました。
私なりに作成してみたのですが、実行しても何も起きませんでした。そのプログラムを以下に示します。原因と解決策を教えていただきたいです。

include

int main(void)
{
int j=1;
int count,i;
for(i=2;i<=100;i++){
while(j<=i-1){
if(i%j==0){
count++;
}
if(count==1){
printf("%d\n",i);
}
j++;
}
}
return 0;
}

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?