当前位置:网站首页>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;
}边栏推荐
- Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
- Message subscription and publishing
- PCB中常用快捷键
- JVM object lifecycle
- fpga阻塞赋值和非阻塞赋值
- 泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
- How to bold text in AI
- 7-8 overspeed judgment
- Common plug-ins for vite project development
- JVM class loading
猜你喜欢

QT learning 22 layout manager (I)

Configure stylelint

牛客网:过河卒

Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)

Exercise 8-8 moving letters

Exercise 10-3 recursive implementation of exponential functions

QT learning 25 layout manager (4)

Redis:字符串類型數據的操作命令

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

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
随机推荐
QT learning 20 standard dialog box in QT (middle)
JS Part III
Strategy, tactics (and OKR)
Leetcode (4) -- find the median of two positively ordered arrays
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
JS first summary
jvm-运行时数据区
愉悦资本新双币基金近40亿元完成首次关账
Article content typesetting and code highlighting
Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
7-7 12-24 hour system
JS matrix zero
Although not necessarily the best, it must be the hardest!
Collection of mobile adaptation related articles
Common mixins
JS continues to explore...
Exercise 6-6 use a function to output an integer in reverse order
GRPC的四种数据流以及案例