Skip to content

Commit 863f659

Browse files
authored
Program To Rotate An Array in Anticlockwise direction.
1 parent 02f39b1 commit 863f659

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main() {
4+
cout<<"Program To Rotate An Array in Anticlockwise direction"<<endl;
5+
int as;
6+
cout<<"Input Array Size"<<endl;
7+
cin>>as;
8+
int array[as];
9+
cout<<"Please input array elements one by one:"<<endl;
10+
for(int i=0;i<as;i++){
11+
cout<<"enter "<<i+1<<" th element"<<endl;
12+
cin>>array[i];
13+
}
14+
15+
int temp[as];
16+
cout<<"please input the shifting constant"<<endl;
17+
cout<<"Your Entered Array Is"<<endl;
18+
for(int i=0;i<as;i++){
19+
20+
cout<<array[i]<<" ";
21+
}
22+
cout<<endl;
23+
int a;
24+
cin>>a;
25+
for(int i=0;i<as;i++){
26+
temp[i]=array[i];
27+
}
28+
for(int i=0;i<as;i++){
29+
if(i-a<0){
30+
array[i-a+as]=temp[i];
31+
}else{
32+
array[i-a]=temp[i];
33+
}
34+
}
35+
cout<<"Your Rotated Array Is"<<endl;
36+
for(int i=0;i<as;i++){
37+
cout<<array[i]<<" ";
38+
}
39+
cout<<endl;
40+
return 0;
41+
}

0 commit comments

Comments
 (0)