C实例
内容代码
内容
非法输入则报错,例如12.3、456abc、abc整除4但不整除100为闰年整除400为闰年
代码
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
char year
[200]={0};
int n
;
int main()
{
printf("请输入年份:\n");
while(scanf("%s",&year
)!=EOF)
{
if (strspn(year
, "0123456789") == strlen(year
))
{
n
=atoi(year
);
if((n
% 4 ==0 && n
%100!=0)||(n
% 400 == 0))
{
printf("%d是闰年\n",n
);
}
else
{
printf("%d不是闰年\n",n
);
}
printf("**************\n");
}
else
{
printf("输入错误\n");
printf("**************\n");
}
}
return 0;
}
转载请注明原文地址: https://lol.8miu.com/read-4868.html