Answer to Question #21573 in C++ for saad
Question #21573
Write a program that reads 5 numbers from the user and print the output according to following pattern
12345
23451
34512
45123
51234
12345
23451
34512
45123
51234
Expert's answer
#include <iostream>
using namespace std;
int main()
{
cout << "please enter 5 numbers" << endl;
int a[5];
& &
for(int i=0;i<5;i++)
{
& cin>>a[i];
& b[i]=a[i];
}
& cout<<endl<<endl;
//////// 1
cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4];
cout<<endl<<endl;
//////// 2
cout<<a[1]<<a[2]<<a[3]<<a[4]<<a[0];
cout<<endl<<endl;
//////// 3
cout<<a[2]<<a[3]<<a[4]<<a[0]<<a[1];
cout<<endl<<endl;
//////// 4
cout<<a[3]<<a[4]<<a[0]<<a[1]<<a[2];
cout<<endl<<endl;
//////// 5
cout<<a[4]<<a[0]<<a[1]<<a[2]<<a[3];
cout<<endl<<endl;
return 0;
}
using namespace std;
int main()
{
cout << "please enter 5 numbers" << endl;
int a[5];
& &
for(int i=0;i<5;i++)
{
& cin>>a[i];
& b[i]=a[i];
}
& cout<<endl<<endl;
//////// 1
cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4];
cout<<endl<<endl;
//////// 2
cout<<a[1]<<a[2]<<a[3]<<a[4]<<a[0];
cout<<endl<<endl;
//////// 3
cout<<a[2]<<a[3]<<a[4]<<a[0]<<a[1];
cout<<endl<<endl;
//////// 4
cout<<a[3]<<a[4]<<a[0]<<a[1]<<a[2];
cout<<endl<<endl;
//////// 5
cout<<a[4]<<a[0]<<a[1]<<a[2]<<a[3];
cout<<endl<<endl;
return 0;
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Dear Drishti
Questions in this section are answered for free. We work on all questions
and publish answers after verification. There is no guarantee of answering
certain question but we are doing our best. Although if you have serious
assignment that requires large amount of work and hence cannot be done for
12345
23451
34512
45123
51234
I need this pattern in C. please help me write the code for this pattern. x
Leave a comment