输入一个年份判断是否为闰年,是就返回TRUE,否则就返回FALSE.cpp

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{   int m,i;
 bool prime;
    prime=true;
    cout<<"请输入一个正整数:";
 cin>>m;
 for(i=2;i<=m-1;i++)
    if(m%i==0)
 {prime=false;
    break;
    }
 if(prime)
  cout<<"是素数"<<endl;
 else
  cout<<"不是素数"<<endl;
 return 0;
}

 

   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 以下是闰年的 Python 代码: year = int(input("请输入一个年份:")) if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print("True") else: print("False") 输入一个年份,程序会年份闰年,如是则True”,False”。 ### 回答2: 这是一个简单的闰年的程序,我将用Python语言编写。 ```python # 用户年份 year = int(input("请输入一个年份:")) # 判断是否闰年 if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0: print("True") else: print("False") ``` 程序首先通过`input()`函数获取用户入的年份,并将其转换为数类型。接下来,使用语句年份闰年: 1. 年份能被4除且不能被100除,或者能被400除的年份都是闰年。 2. 如满足上述,则"True",表示该年份闰年则,"False",表示该年份不是闰年。 以上就是一个用于闰年的简单程序,通过输入一个年份,程序会其是闰年相应的结。 ### 回答3: 可以使用以下的C++程序来用户入的年份闰年: ```cpp #include <iostream> using namespace std; int main() { int year; cout << "请输入一个年份:"; cin >> year; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { cout << "True" << endl; } else { cout << "False" << endl; } } else { cout << "True" << endl; } } else { cout << "False" << endl; } return 0; } ``` 该程序首先要求用户输入一个年份,然后通过使用取余运算符(%)来年份闰年。具体的逻辑如下: 1. 若年份能被4除,则有可能是闰年; 2. 若年份能被100除,但不能被400除,则不是闰年; 3. 若年份既能被4除,又能被400除,则为闰年; 4. 对于其他情况,不是闰年。 根据以上的逻辑,如用户入的年份闰年,则True”,False”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值