第3章第6题
#include<stdio.h>
int main()
{
int n = 0;
for (int year = 1000; year<= 1999; year++)
{
if ((year % 400 == 0 || year % 4 == 0 && year % 100 != 0))
{
printf("%d ", year);
n++;
}
if (n == 3)
{
printf("\n");
n = 0;
}
}
return 0;
}
第3章第10题
#include<stdio.h>
int main()
{
int j = 0;
while (j < 5)
{
int year = 0;
int month = 0;
printf("请输入年份:");
scanf_s("%d", &year);
printf("请输入月份:");
scanf_s("%d", &month);
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: printf("该月有31天"); break;
case 2:if (year % 400 == 0 || year % 4 == 0 && year % 10 != 0) printf("该月有29天"); else printf("该天有28天"); break;
case 4:
case 6:
case 9:
case 11:
printf("该天有30天");
break;
default:
printf("月份输入错误");
}
j++;
printf("\n");
}
return 0;
}
第3章第24题
#include<stdio.h>
int main()
{
for (int i = 100; i < 1000; i++)
{
int sum = 0;
for (int j = 1; j < i; j++)
{
if (i % j == 0)
{
sum += j;
}
}
if (sum == i)
{
printf("%d\n", i);
}
}
return 0;
}
第3章第28题
#include<stdio.h>
int main()
{
double sum = 0;
for ( double i = 1; 1.0/i > 0.00001; i++)
{
sum += 1 / i;
}
printf("%lf", sum);
return 0;
}