读入正整数 输入从n到1,数之间用空格间隔开,每15个数换行 如20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
读入整数对中间分隔情况没有固定标准,只要不是数字就行。读入正整数20,后面20个数根本不需要输入啊。你的意思是输出吧?
int main()
{
int n;
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
printf("%d ",i);
if(i%15 == 0)
printf("\n");
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "请输入一个整数n:";
cin >> n;
for (int i = n; i > 0; --i) {
if ((n-i) % 15 == 0)
cout << "\n";
cout << i <<" " ;
}
return 0;
}
运行结果:
请输入一个整数n:20
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6
5 4 3 2 1
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
for (int i = n; i > 0; --i) {
printf("%d ", i);
if ((n - i + 1) % 15 == 0)
printf("\n");
}
printf("\n");
return 0;
}
// Output
20
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6
5 4 3 2 1
C++
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = n; i > 0; --i) {
cout << i << " ";
if ((n - i + 1) % 15 == 0)
cout << endl;
}
cout << endl;
return 0;
}
// Output
50
50 49 48 47 46 45 44 43 42 41 40 39 38 37 36
35 34 33 32 31 30 29 28 27 26 25 24 23 22 21
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6
5 4 3 2 1
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632