c++试题,急寻帮助,
- 提问者网友:放下
- 2021-05-03 23:36
- 五星知识达人网友:第四晚心情
- 2021-05-04 00:03
第一题:
#include"iostream"
using namespace std;
void main()
{int year,flag=0;
cout<<"Enter a year:";
cin>>year;
if(year%400==0||year%4==0&&year%100!=0) flag=1;
if(flag==0) cout<<"No\n";
else cout<<"Yes\n";
cout<<endl;
}
第二题:
#include"iostream"
using namespace std;
int div(int n)
{if(n%5==0) return 1;
else return 0;
}
void main()
{int i,total=0;
for(i=0;i<=100;i++)
if(div(i)==1)
total+=i;
printf("%d\n",total);
}
- 1楼网友:低音帝王
- 2021-05-04 03:32
#include <iostream>
using namespace std;
int main()
{
int year;
cout<<"input year!"<<endl;
cin>>year;
if((year%4==0&&year%100!=0)||(year%400==0))cout<<"yes!"<<endl;
else cout<<"no!"<<endl;
return 0;
}
- 2楼网友:行路难
- 2021-05-04 02:15
1
#include<iostream.h> void main() { void loop(int n); loop(2009); } void loop(int n) { if(n%4==0&&n%100!=0||n%400==0) cout<<"闰年"; else cout<<"不是闰年"; } 2
#include<iostream.h> void main() { int loop(int n); cin>>n; cout<<loop(n); } int loop(int n) { int sum=0; int i; for(i=1;i<=100;i++) if(i%5==0) sum+=i; if(sum%n==0) return 1; else return 0; }
- 3楼网友:慢性怪人
- 2021-05-04 01:29
第一题:
#include< iostream > using namespace std;
int main() { int n; cout << "输入年份: "; cin >> n; if( n % 4 ==0 && ( n % 100 != 0 || n % 400 ==0 )) cout << n << "是闰年" << endl; else cout << n << "不是闰年" << endl; return 0; }
第二题:
#include< iostream > using namespace std;
int div( int n ) { return !( n % 5 ); //对5求余,能被5整除时,余数为0,所以取反为1. 否则取反为0 } int main() { int sum = 0; for( int i = 1; i <= 100; ++i ) //从1循环到100 { if( div( i ) ) sum += i; } cout << sum << endl; return 0; }