Circular shift method of C language array elements

  • 2020-06-07 04:56:40
  • OfStack

As shown below:


/*C Circular shifts of language array elements */

#include <stdio.h>

int main()
{
 int num[5],num1[5];
int i, j,k=1;
int t,n;
 
printf(" Please enter the 5 The number of :");

for(i=0;i<5;i++)
{
scanf("%d",&num[i]); // Reads the number into an array num
}
  printf(" Please enter the number of cycles :");
scanf("%d",&n);
 
 for(j=0;j<n;j++)     // Control conversion times 
 {
 for(i=0;i<5;i++)
 { 
 
 num1[k]=num[i]; 
 k++;
 
 if(k==5)k=0; //k=5 , resets the array from the first 1 Start reading in the elements 
 }

 for(i=0;i<5;i++)
 {
 num[i]=num1[i]; // Replace the swapped array with the new array 1 An array 
 }
 }

 printf(" The converted array is  :");

 for(i=0;i<5;i++)
 {
 printf("%d ",num[i]);// Output the converted array 
 }
 printf("\n");
 return 0;
}

Related articles: