当前位置:网站首页>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;
}边栏推荐
- Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
- 【吉林大学】考研初试复试资料分享
- Exercise 8-2 calculate the sum and difference of two numbers
- TS code automatically generates JS
- QT learning 19 standard dialog box in QT (top)
- Uniapp skills - scrolling components -1
- 好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
- Interface for querying IP home
- Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
- The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
猜你喜欢

天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪

Interface for querying IP home

Jiuyi cloud black free encryption free version source code

FPGA test method takes mentor tool as an example
[email protected] Nanoparticles) | nano metal organic framework carry"/>Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
[email"/>Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
![[clean up the extraordinary image of Disk C]](/img/0d/331115bc5d82d6337ae975a08494b2.jpg)
[clean up the extraordinary image of Disk C]

Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
随机推荐
allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取
JS continues to explore...
concat和concat_ws()区别及group_concat()和repeat()函数的使用
C library function - qsort()
Global event bus
JVM garbage collector
JVM object lifecycle
Uniapp skills - scrolling components -1
Selenium browser (1)
GRPC的四种数据流以及案例
Message subscription and publishing
Understanding of closures
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
中国锂电池电解液行业市场专项调研报告(2022版)
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
牛客网:过河卒
JVM class loading
JS get DPI, PX to cm, cm to PX
Although not necessarily the best, it must be the hardest!
Article content typesetting and code highlighting