forked from ShreeyansB/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightRotate.c
More file actions
46 lines (40 loc) · 773 Bytes
/
RightRotate.c
File metadata and controls
46 lines (40 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
void Input(int *P, int N) {
int i;
for(i=0;i<N;i++) {
scanf("%d",&P[i]);
}
}
void RotateOnce(int *P, int N) {
int i,l;
l=P[N-1];
for(i=N-1;i>0;i--) {
P[i]=P[i-1];
}
P[0]=l;
}
void RotatekTimes(int *P, int N, int K) {
int i;
for(i=0;i<K;i++) {
RotateOnce(P,N);
}
}
void Display(int *P, int N) {
int i;
for(i=0;i<N;i++) {
printf("%d ",P[i]);
}
}
int main() {
int n=0,a[50],k;
printf("Enter Array Size: ");
scanf("%d",&n);
printf("Enter the elements of Array: ");
Input(a,n);
printf("Enter how many times you want to rotate right: ");
scanf("%d",&k);
RotatekTimes(a,n,k);
printf("New Array: ");
Display(a,n);
return 0;
}