#include<stdio.h>
//输出100之内的所有素数
int main()
{
int i;
int j;
int flag = 1;
for(i = 2;i <= 100;i++)
{
for(j = 2;j <= i / 2;j++)
{
if(i % j ==0)
{
flag = 0;
break;
}
}
if(flag == 1)
{
printf("%d\n",i);
}
flag = 1;
}
return 0;
}
扩展资料
#include <stdio.h>
int main()
{
int a;
for (int i = 2; i < 100; i++)
{
int a = 0;
/* code */
for (int j = 2; j < i; j++)
{
/* code */
if (i % j == 0)
{
/* code */
a++;
}
}
if (a == 0)
{
/* code */
printf("%d is sushu\n", i);
}
else
{
/* code */
printf("%d is not sushu\n", i);
}
}
return 0;
}