P1427小鱼的数字游戏-C++编程解析-数组

题目
解题思路:
通过题目分析,要想小鱼把这串数字倒着念出来,需要小鱼先将这串数字记录下来,而小鱼的记忆很短,所以我们可以利用数组将这串数字保存起来。然后,将数组内的数据从末尾到首端依次输出即可。
程序:

#include<iostream>
using namespace std;
int main(){
	int num[100] = {0};  //小鱼的大脑 
	int total = 0;       //数字个数 
	while(true){
		int n;
		cin>>n;
		if(n == 0)       //数字结束 
			break;
		num[total++] = n;
	}
	for(int i = total - 1;i >= 0;i--)  //输出 
		cout<<num[i]<<" ";
	return 0;
}

程序运行结果:
在这里插入图片描述
问候
问候2

发布了34 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/xingzhe_666/article/details/101448400
今日推荐