当前位置:网站首页>Use the for loop to calculate the odd and even sums in 1-100 [method 2]
Use the for loop to calculate the odd and even sums in 1-100 [method 2]
2022-06-21 22:17:00 【Programming expert】
source :《 Information Science Olympiad all in one 》p55
【 Title Description 】
utilize for loop , Separate calculation 1-100 Sum of odd numbers in 、 An even sum .
The code is as follows :
notes : Code for reference only , There is not only one solution .
//for loop 【 Method 2 】
#include<iostream>
using namespace std;
int main(){
int sum1=0,sum2=0;
for(int i=1;i<=100;i++) {
if(i%2==0) sum1=sum1+i;else sum2=sum2+i;}
cout<<"sum1="<<sum1<<" sum2="<<sum2;
return 0;
}
边栏推荐
- Font size in DataGridView of C #
- 阿里云容器服务负责人易立:云原生如何解企业降本提效难题?
- Shell script simple syntax
- 联系五心红娘脱单
- The order management system realizes the unified management of enterprise order inventory
- 利用while循环,分别计算1-100中奇数的和、偶数的和【方法一】
- Guangdong CDC reminds: the summer vacation is coming, so the returned college students can "return home" safely
- 【深入理解TcaplusDB技术】如何实现Tmonitor单机安装
- Background and specificity of Worthington elastase
- 利用do while循环,分别计算1-100中奇数的和、偶数的和【方法一】
猜你喜欢

基于OpenCVSharp的001新建工程项目

棋牌类游戏

新能源行业商业采购协同系统:赋能新能源行业采购业务,提升产业协同

利用tRNAscan-SE做tRNA分析

【深入理解TcaplusDB技術】TcaplusDB構造數據

【深入理解TcaplusDB技术】TcaplusDB业务数据备份

赋·新生,链·未来!城链科技产业赋能创新发展大会隆重举行
![Luogu p1514 [noip2010 improvement group] water diversion into the city](/img/62/6bab87231074b87770e90257ef7bbc.jpg)
Luogu p1514 [noip2010 improvement group] water diversion into the city

Enterprise data leakage prevention solution sharing

五分钟带你了解云原生
随机推荐
【深入理解TcaplusDB技术】TcaplusDB构造数据
洛谷P1608 路径统计 题解
Using bioedit to do multiple sequence consistency alignment
HIC Pro | HIC data processing tool
Communication failure between botu simulation HMI and real 1200plc
As we media, why can some people earn more than 10000 yuan a month, but you can only earn a few yuan a month?
File i/o
B2B mall website helps enterprises speed up distribution and build an efficient and intelligent B2B online distribution platform
弗吉尼亚大学:Ingy ElSayed-Aly | 多智能体强化学习中的基于逻辑的奖励形成
刷题笔记(十七)--二叉搜索树:关于属性问题
提升方法(上)AdaBoost
Worthington胰蛋白酶解决方案
传承百年经典的瑞吉管家静待您的优雅旅程再次开启
Mafft|multi sequence alignment tool
Specificity and application of Worthington Papain
新能源行业商业采购协同系统:赋能新能源行业采购业务,提升产业协同
洛谷P5440 【XR-2】奇迹 题解
IQtree|构建进化树的软件
Worthington木瓜蛋白酶特异性和应用
Fu · new life, chain · future! The conference on enabling innovation and development of urban chain technology industry was held grandly