c++简单编程

来源:百度知道 编辑:UC知道 时间:2024/09/23 14:00:20
编写程序,输出从公元1600到2000年中所有闰年的年份?
每行输出五个。
请详细解释用C++如何每行输出对齐的五个数。

#include <iostream.h>

void main()
{ int i,j=0;
for(i=1600;i<=2000;i+=4)
{ if((i%4==0&&i%100!=0)||i%400==0)
{ cout<<i<<' ';
j++;
if(j%5==0) cout<<"\n";
}
}

}

int year = 1600;
int count = 0;
while(year <= 200)
{
if(year % 100 == 0)
{
if(year % 400 == 0)
{
count++;
cout << year << '\t';
if(cout % 5 == 0)
cout << end;
}
}
else(year % 4 == 0)
{
count++;
cout << year << '\t';
if(cout % 5 == 0)
cout << end;
}
year++;
}

用制表符可以实现对齐