当前位置:网站首页>7-14 sum integer segments (C language)
7-14 sum integer segments (C language)
2022-07-03 14:14:00 【Big fish】
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
PS:
It is a problem of counting and summing cycles . Test point 1 If not , There is a problem with the output format , Output one more line feed . Note that when the number of output numbers is 5 The integral times of , There may be more than one line feed output , Therefore, there is no need to wrap the last line .
Attach code :
#include <stdio.h>
int main(){
int a,b,i;
int sum = 0;
int couter = 0; // To count
scanf("%d %d",&a,&b);
for(i=a;i<=b;i++){ //i Used to record output numbers
sum += i;
couter++;
printf("%5d",i); // Output 5 Characters
if(couter%5 == 0 && i!=b){ // When the count reaches 5 When it's time , It's a new line , And the last line does not need to wrap
printf("\n");
}
}
printf("\n");
printf("Sum = %d",sum);
return 0;
}边栏推荐
- jvm-类加载
- FPGA test method takes mentor tool as an example
- [acnoi2022] guess numbers
- 中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
- 关于回溯问题中的排列问题的思考(LeetCode46题与47题)
- Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
- Exercise 9-1 time conversion
- MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
- Exercise 6-1 classify and count the number of characters
- Current situation, analysis and prediction of information and innovation industry
猜你喜欢

Redis: operation command of string type data

7-9 find a small ball with a balance

Current situation, analysis and prediction of information and innovation industry

jvm-运行时数据区

可编程逻辑器件软件测试

FPGA test method takes mentor tool as an example

Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them

QT learning 24 layout manager (III)

Exercise 10-3 recursive implementation of exponential functions

Article content typesetting and code highlighting
随机推荐
C library function - qsort()
Toast UI editor (editor allows you to edit your markup document using text or WYSIWYG, with syntax highlighting, scrolling synchronization, real-time preview and chart functions.)
Leetcode(4)——寻找两个正序数组的中位数
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
QT learning 23 layout manager (II)
Configure stylelint
Programmable logic device software testing
Analysis of the characteristics of page owner
How to bold text in AI
JS first summary
fpga阻塞赋值和非阻塞赋值
Solution to failure or slow downloading of electron when electron uses electron builder to package
7-11 calculation of residential water charges by sections
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
selenium 浏览器(1)
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
JS general form submission 1-onsubmit
Common mixins
Eight sorts
jvm-运行时数据区