信息学奥赛一本通 第一部分 C++语言 --> 第四章 循环结构的程序设计 题号 提交数第一节 for语句 全答案(有题号,自己对应)

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, cnt = 0;
	cin >> a >> b;
	for(int i = a; i <= b; i++){
		if(i % 17 == 0){
			cnt += i;
		}
	}
	cout << cnt << "\n";
	return 0;
}
2016 【例4.1】for循环求和
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, sum = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		sum += i;
	}
	cout << sum << "\n";
	return 0;
} 
2017

【例4.2】输出偶数

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i % 2 == 0){
			cout << i << " ";
		}
	}
	return 0;
} 
2018 【例4.3】输出奇偶数之和
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, c1 = 0, c2 = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i % 2 == 0){
			c1 += i;
		}
		else{
			c2 += i;
		}
	}
	cout << c1 << " " << c2 << "\n";
	return 0;
}
2019 【例4.4】求阶乘
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long c = 1;
	cin >> n;
	for(int i = 1; i <= n; i++){
		c *= i;
	}
	cout << c << "\n";
	return 0;
}
1059 求平均年龄
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a, c = 0;
	for(int i = 1; i <= n; i++){
		cin >> a;
		c += a;
	}
	cout << fixed << setprecision(2) << 1.0 * c / n << "\n";
	return 0;
}
1060 均值
#include<iostream>
#include<stdio.h>
using namespace std;
double a,c,b[101];
int main() {
	cin>>a;
	for(int i=1; i<=a; i++) {
		cin>>b[i];
		c+=b[i];
	}	
	c/=a;
	printf("%0.4f",c);
}
1061
  • 19
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值