素数,99乘法表,闰年

1.打印100~200之间的素数(素数指除了1和他本身外,无法被其他自然数整除的数)
程序代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
int b;
for (a = 100; a <= 200; a++)
{
for (b = 2; b < a; b++)
{
if (a%b == 0)
break;
}
if (b >= a)
{
printf("%d\n", a);
}
}
system(“pause”);
return 0;
}

运行结果如下:
在这里插入图片描述
2.打印99乘法表
程序代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
int b;
int s;
for (a = 1; a < 10; a++)
{
for (b = 1; b <=a; b++)
{
s = a * b;
printf("%d*%d=%d\t", b, a, s);
}
printf("\n");
}
system(“pause”);
return 0;
}
程序运行如下:
在这里插入图片描述
3.判断1000~2000年之间的闰年 (闰年指能被4整除且不能被100整除,或能被400整除的年份)
程序代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a;
for (a = 1000; a <= 2000; a++)
{
if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0)
printf("%d\t", a);
}
system(“pause”);
return 0;
}
运行结果如下:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42644428/article/details/88574685