File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ # coding: utf-8
3
+
4
+ # In[ ]:
5
+
6
+
7
+
8
+
9
+ arr = list ();
10
+ n = input ("Enter the number of elements you want in the array: " )
11
+
12
+ print ("Enter the array elements one by one:" )
13
+ for i in range (int (n )):
14
+ ele = input ()
15
+ arr .append (int (ele ))
16
+
17
+ #Display the original array
18
+ print ("Array before rotation is: " )
19
+ for i in range (0 , len (arr )):
20
+ print (arr [i ])
21
+
22
+ #Rotate the given array by 3 times towards left
23
+ for i in range (0 , 3 ):
24
+ #Stores the first element of the array
25
+ first = arr [0 ]
26
+
27
+ for j in range (0 , len (arr )- 1 ):
28
+ #Shift element of array by one
29
+ arr [j ] = arr [j + 1 ]
30
+
31
+ #First element of array will be added to the end
32
+ arr [len (arr )- 1 ] = first
33
+
34
+ print ()
35
+
36
+ #Display the array after 3 left rotations
37
+ print ("Array after 3 left rotations is: " );
38
+ for i in range (0 , len (arr )):
39
+ print (arr [i ])
40
+
You can’t perform that action at this time.
0 commit comments