第一次

来源:互联网 发布:网络作家协会怎么加入 编辑:程序博客网 时间:2024/05/20 16:39
1.素数
#include<stdio.h>
int main()
{
 int i = 0;
 int count = 0;
 for (i = 100; i <= 200; i++)
 {
  int j = 0;
  for (j = 2; j < i; j++)
  {
   if (i%j == 0)
   {
    break;
   }
  }
  if (i == j)
  {
   count++;
   printf("%d ", i);
  }
  
 }
 printf("\ncount=%d\n", count);
 system("pause");
 return 0;
}
2.乘法表
#include<stdio.h> 
#include<math.h>
int main()
{
 int i = 0;
 int j = 0;
 for (i = 1; i <= 9; i++)
 {
  for (j = 1; j <= i; j++)
  {
   printf("%d*%d=%d ",i,j,i*j);
  }
  printf("\n");
 }
 system("pause");
 return 0;
}
3.闰年
#include<stdio.h>
int main()
{
 int year = 0;
 int count = 0;
 for (year = 1000; year <= 2000; year++)
 {
  if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
  {
   printf("%d ",year);
   count++;
  }
 }
 printf("\ncount=%d\n",count);
  system("pause");
  return 0;
}

原创粉丝点击