学习C++算法入门第二天

发布时间 2023-12-12 17:09:03作者: AlbertKs

头文件#include<iostream>  i=input ,o=output
using namespace std;

头文件函数:https://blog.csdn.net/qq_32699009/article/details/104615792 参考这个

Hello World!---C学过,第一次接触C++,开启新的语言学习

cin>>输入;cout<<输出<<endl;

 

啥是闰年?---非整百年:能被4整除的为闰年。整百年:能被400整除的是闰年

#include<iostream>
using namespace std;
int main(){
    int year;
    cin>>year;
    if((year%4==0&&year%100!=0)||year%400==0){
        cout<<"闰年"<<endl; 
    }else{
        cout<<"平年"<<endl; 
        
    } 
}

水仙花数?指一个3位数,它的各位数字的3次幂之和等于它本身。
例如,3位数153是水仙花数,各位数字的立方和13 +53 +33 = 153。

#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n,a,b,c;
    cin>>n;
    a=n%10;
    b=(n/10)%10;
    c=(n/100)%10;
    if(n==(a*a*a+pow(b,3)+c*c*c)){
        cout<<n<<"是水仙花数"<<endl; 
    }else{
        cout<<n<<"不是水仙花数"<<endl; 
    } 
}