第一次写博客有点蒙圈,while it's ok,just do it,nothing is impossible to the willing heart.当然其中有很多错误,希望各位看官指出,一起学习,一起进步。
判断闰年输出1000到2000的闰年,并且输出个数。
代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int year, count = 0; //给闰年个数赋初始值0;
for (year = 1000; year <= 2000; year++)
if ((year % 4 == 0 && year % 100 != 0 || (year % 400 == 0)))//判断闰年的条件可以被4整除不能被100整除且能被400整除;
{
count++;
printf("%d ", year);
if (count % 12 == 0)//闰年的个数满12个后换行
printf("\n");
}
printf("\n");
printf("输出闰年的个数为d\n ", count);//输出闰年的个数
system("pause");
return 0;
}
开始的时候输出结果不清晰,加上一个 if (count % 12 == 0)//闰年的个数满12个后换行 printf("\n");
输出九九乘法口诀表:
代码如下:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, j;
for (i = 1; i <= 9;i++)
{
for (j = 1; j <= i;j++)
printf("%d*%d=%d " ,i,j, i*j);//输出i*j的表达式;
printf("\n");
}
system("pause");
return 0;
}
用VS的朋友可能都会经历输出结果显示闪退的情况,加一个
#include<stdlib.h>和system("pause"); 就好了,不是很明白,应该是停止的指令。
转载请注明原文地址: https://ju.6miu.com/read-1124382.html