-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray_rotation.c
37 lines (36 loc) · 922 Bytes
/
array_rotation.c
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
// This programm is for array right rotate
#include<stdio.h>
int main(){
int size,rotation;
printf("Enter the size of the array: ");
scanf("%d",&size);
int arr[size];
printf("Enter array element: ");
for (int i = 0; i < size; i++)
{
scanf("%d",&arr[i]);
}
printf("The array is : ");
for (int i = 0; i < size; i++)
{
printf("[%d] ",arr[i]);
}
printf("\n");
printf("Enter how many time u want to rotate: ");
scanf("%d",&rotation);
for (int i = 0; i < rotation; i++)
{
int lastelmnt = arr[size-1];
for (int j = size-1; j >= 0; j--)
{
arr[j+1] = arr[j];
}
arr[0] = lastelmnt;
}
printf("Now The array is : ");
for (int i = 0; i < size; i++)
{
printf("[%d] ",arr[i]);
}
return 0;
}