1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2

2 3 4 5 1

 
(1)运用循环嵌套,并设置中间变量转换
//1、新建一个数组
//2、输入内容并存储
//3、输出结果
#include<iostream>
using namespace std;

int main()
{
    int temp;
    int a[5]={1,2,3,4,5};
    for(int m=0;m<5;m++)
    {
        cout<<a[m]<<" ";
    }
    cout<<endl;

    for(int i=0;i<5;i++)
    {
        temp=a[4];//先将最后一位取出来放到中间变量保护起来
        for(int j=4;j>=1;j--)
        {
            a[j]=a[j-1];//每一位向后移一位
        }
        a[0]=temp;//在将保护的值赋给首位

        if(a[0]!=1)//用于输出
        {
            for(int j=0;j<5;j++)
            {
                cout<<a[j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}

(2)我不会告诉你,这才是最简便的方法:

#include<iostream>
using namespace std;

int main()
{
    cout<<"1 2 3 4 5"<<endl;
    cout<<"5 1 2 3 4"<<endl;
    cout<<"4 5 1 2 3"<<endl;
    cout<<"3 4 5 1 2"<<endl;
    cout<<"2 3 4 5 1"<<endl;
    
    return 0;
}

 

相关文章:

  • 2021-06-21
  • 2021-12-19
  • 2021-05-17
  • 2021-12-22
  • 2022-01-01
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-10-19
  • 2021-06-24
  • 2021-04-26
  • 2021-07-04
  • 2021-05-26
相关资源
相似解决方案