啊哈磊_编程从这里起步

标题: 输入一个数,判断它是不是闰年 [打印本页]

作者: shanglingxi    时间: 2020-3-28 14:48
标题: 输入一个数,判断它是不是闰年
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5.     int a;
  6.     scanf("%d",&a);
  7.     if (a/4=0)
  8.    
  9.         printf ("yes");
  10.     }
  11.     else
  12.     {
  13.         printf("no");
  14.     }
  15.     return 0;
  16. }
复制代码

作者: 嘟嘟编程    时间: 2020-3-28 15:56
本帖最后由 嘟嘟编程 于 2020-3-28 16:00 编辑

if里是==,不是=
而且第一个if少了个大括号

"/4"是求结果,这里要求余数,应该是"%4"
如果要判断闰年,还要判断结尾有两个以上的0要判断是否能整除400
代码如下:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    scanf("%d",&a);
    if (a%4==0)  //是==,%号表示取余
    {              //少了个大括号
        printf ("yes");
    }
    else
        if(a%100==0&&a%400==0)/*结尾有两个0,即除100*/
        {             //再加个判断
            printf("yes");
        }
        else
        {            
            printf("no");
        }
    return 0;
}






欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2