当前位置:网站首页>L1-008 sum integer segments
L1-008 sum integer segments
2022-07-21 19:23:00 【Alter_ r】
The original title is
Given two integers A and B, Output from A To B All the integers of and the sum of these numbers .
Input format :
Enter... On one line 2 It's an integer A and B, among −100≤A≤B≤100, Separated by spaces .
Output format :
First, output sequentially from A To B All integers of , Every time 5 A line of numbers , Each number accounts for 5 Character width , Align right . Finally, in a line, press Sum = X
Output the sum of all the numbers X
.
sample input :
-3 8
sample output :
-3 -2 -1 0 1
2 3 4 5 6
7 8
Sum = 30
#include <bits/stdc++.h>
using namespace std;
int main()
{
int A,B,sum = 0,k = 0;
cin >> A >> B;
for(int i = A; i <= B; i++)
{
k++;
printf("%5d",i);
sum += i;
if(k % 5 == 0)
printf("\n");
}
// printf("\n"); Notice the line breaks here
if(k % 5 != 0)
printf("\n");
cout << "Sum = " << sum;
return 0;
}
边栏推荐
- Software test interview question: how to test a paper cup?
- [QT入门篇]信号槽机制
- LBA converted to CHS formula
- Light the first LED
- [introduction to QT] signal slot mechanism
- Distributed General service layer cache design
- 06 提取数据的json字符串
- 05 正则表达式语法
- 出现“TypeError: ‘str‘ object does not support item assignment”的原因
- 分布式.高性能
猜你喜欢
[QT入门篇]窗口类的应用
FTP服务配置
Ardunio development - use of soil sensors
Teach you how to install MySQL database by hand
Distributed High concurrency concepts and design goals
Phpstudy_ Pro builds sqli labs shooting range for SQL injection test
手把手教你安装MySQL数据库
SAP IDOC教程:定义,结构,类型,格式和表格-019
程序员第一课“hello word”,你知道网工第一课吗?
MYSQL08_ Overview of sub query, single row, multi row, related sub query
随机推荐
四种bean拷贝工具对比
05 regular expression syntax
NFS service configuration
ThreadLocal
SAP smartforms 打印失败 消息类型:SSFCOMPOSER 消息号:601 (货币和数字字段设置参考及格式)
Software testing interview question: what are the common design methods of test cases for black box testing? Please use specific examples to illustrate the application of these methods in test case de
QT(37)-mosquitto-MQTT客户端
Seata之AT模式原理详解(三)
Light the first LED
SAP IDOC教程:定义,结构,类型,格式和表格-019
Plantuml draw link diagram
MySQL进阶(B)
How to realize copyright protection of Digital Collections
[information retrieval] implementation of information retrieval system
Create high-performance applications and continuously optimize the user experience
Spark RDD, application case of spark SQL
Force uninstall of additional domain controllers
plantuml画链路图
Arduino I2C for TCA9548A应答扫描程序
toast_ tuple_ Question of threshold