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;
}

运行结果如下:
素数,99乘法表,闰年
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;
}
程序运行如下:
素数,99乘法表,闰年
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;
}
运行结果如下:
素数,99乘法表,闰年

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-12-05
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2021-12-23
  • 2021-12-10
相关资源
相似解决方案