File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments