一、N-S流程图;
二、运行结果;
三、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <math.h>int main()
{//初始化变量值;int i = 0;int j = 0;int n = 0;int a[101] = { 0 };//循环填充数组a的值;for (i = 1; i <= 100; i++){//循环填充;a[i] = i;//去掉a[1];a[1] = 0;}//循环判断素数;for (i = 2; i <= sqrt(100); i++){//内层循环判断;for (j = i + 1; j <= 100; j++){//判断是否已经判断过了;if (a[i] != 0 && a[j] != 0){//判断素数;if (a[j] % a[i] == 0){//素数替换为0;a[j] = 0;}}}}//换行;printf("\n");//提示;printf("100以内的素数为:\n");//循环输出素数;for (i = 2, n = 0; i <= 100; i++){//判断不为0打印;if (a[i] != 0){//打印结果;printf("%5d", a[i]);n++;}//一行打印10个;if (n == 10){//换行;printf("\n");//初始化n的值;n = 0;}}//换行;printf("\n");return 0;
}