当前位置:网站首页>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;
}边栏推荐
- 2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
- 可编程逻辑器件软件测试
- Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
- 小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
- jvm-运行时数据区
- QT learning 20 standard dialog box in QT (middle)
- 7-9 find a small ball with a balance
- TS code automatically generates JS
- JS first summary
- Similarities and differences of sessionstorage, localstorage and cookies
猜你喜欢

Exercise 10-1 judge the three digits that meet the conditions

Exercise 6-2 using functions to sum special A-string sequences

小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。

7-7 12-24 hour system

QT learning 24 layout manager (III)

Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

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

Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?

Page generation QR code
随机推荐
Uniapp tips - set background music
Duet date picker (time plug-in that can manually enter the date)
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
protobuf与grpc
超简单手机地图开发
Interface for querying IP home
Exercise 10-1 calculate the sum of 1 to n using recursive functions
[clean up the extraordinary image of Disk C]
jvm-运行时数据区
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
x86汇编语言-从实模式到保护模式 笔记
C language,%d% Difference between 2D%2d%02d
Reflection -- basic usage
Message subscription and publishing
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
JS general form submission 1-onsubmit
Strategy, tactics (and OKR)
JS get DPI, PX to cm, cm to PX
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)