w3codeworld logo
  • Home
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#
  • PHP
  • Codeigniter
  • Laravel
  • Articles
  1. Home
  2. Articles
  3. Write a c program to make a circular rotation of an array by k positions using the loops
  • PHP
  • Codeigniter
  • Laravel
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#

Write a c program to make a circular rotation of an array by k positions using the loops

  • Author: Admin
  • Last Updated: 2021-01-06
  • Category: C

Write a c program to make a circular rotation of an array by k positions using the loops. In this program, you will learn how to make a circular rotation of an array by k positions using the loops.

 

Take an example to make this circular rotation through a c program:

// Write a c program to make a circular rotation
// of an array by k positions using the loops
#include <stdio.h>
#define N 100

int main()
{
    int e, r, d;
    int arru[N];
    // e is the number of array elements
    // r is the number of rotations of the array
    // d is the number of indexes to display
    // arru is the array container

    printf("-----Enter the number of elements of the array-----\n");
    scanf("%d", &e);

    printf("\n-----Enter the number of rotations of the array-----\n");
    scanf("%d", &r);

    printf("\n-----Enter the number of indexes to be displayed-----\n");
    scanf("%d", &d);

    printf("\n-----Input the array elements-----\n");
    for (int i = 0; i < e; i++)
    {
        scanf("%d", &arru[i]);
    }

    printf("\n\n------The Array Elements are------\n");
    for (int i = 0; i < e; i++)
    {
        printf("%d ", arru[i]);
    }
    printf("\n");

    // Remove the number of full array rotations from k
    r %= e;

    for (int i = 0; i < d; i++)
    {
        int in;
        printf("\n------Enter the index of the array to be displayed------\n");
        scanf("%d", &in);

        printf("\n------The element in the array is------\n");

        // Calculate the new index
        printf("%d\n", arru[(e + in - r) % e]);
    }

    return 0;
}

 

Output:

-----Enter the number of elements of the array-----
4

-----Enter the number of rotations of the array-----
2

-----Enter the number of indexes to be displayed-----
2

-----Input the array elements-----
12 34 56 43


------The Array Elements are------
12 34 56 43 

------Enter the index of the array to be displayed------
2

------The element in the array is------
12

------Enter the index of the array to be displayed------
3

------The element in the array is------
34

 

 

Tags:

# write a program to the right rotation of array in c language

# write a c program to reversal algorithm for array rotation

# write a c program to juggling algorithm for array rotation

# write a program to shifting elements in an array c language

 

Related Articles

Write a c program to make a circular rotation of an array by k positions using the loops Write a c program to rotate the matrix by k times in a clockwise direction using the function Write a c program to print a hollow square star pattern with diagonal using loops (for and while loop) How to rearrange positive and negative numbers in array in c language How to print a star pattern without using loop in the c programming language Write a program to find the decimal to octal conversion in c language using the while loop Write a c program to convert an array into zig-zag fashion using the function Write a program of spiral pattern printing in c language Write a c program to find the sum of a zig-zag pattern in a given matrix using the recursion Write a program to find the transpose of a matrix in c language How to print the hollow diamond pattern in c language How to find the sum of each row and column of a matrix in c language Write a program to make transformation matrix rotation 90 degrees clockwise in c language Write a program to check an integer number is an automorphic number or not in the c language Write a c program by using call by reference in cyclic order to swap the two numbers Write a c program to convert binary to decimal and vice versa using the function Write a c program to store information of a student using the structure with the for loop Make a c program to reverse a sentence using recursion How to write a c program to find the sum of natural numbers using recursion Write a c program to display characters from a to z using the for loop Write a program to find quotient and remainder in c language Write a program to print the matrix pattern in c language using the for loop Write a program to print the rhombus pattern in the c language of the stars using the for loop Write a program to draw the half pyramid pattern in c language of stars using the for loop Write a c program to draw a rectangle using for loop Write a program to print the left & right arrow pattern in c language Write a program to print Floyd's triangle number pattern in c language Write a program to print the pascal triangle pattern in c language Write a program to print the butterfly pattern of the numbers in c programming by using the for loop C program to print diamond pattern of stars by using the for loop C program to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator Write a program to check an integer number is a prime or composite number in c language by using the while & for loop How to check whether a number is an integer or float in c language by using the while loop C program to find factors of a number using while loop & for loop C program to check the input integer number is an Armstrong number using the for loops & while loops How to swap the two integers or real numbers without using the third variable in the c language C program to convert the reverse case of an input character C program to check leap year using the if-else and by using the switch case statement C program to find the roots of a quadratic equation using the sqrt() function with the if-else condition C program to find GCD of two numbers using the while loop and using the for loop C program to find LCM of two numbers using for loop and with GCD calculation C program to calculate the power of N number using for loop and by using pow function C program to find the Normal & Trace of a square matrix by using the for loop C program to multiply two same dimension matrices by using the for loop C program to find the SUM of the N input numbers using arrays with for loop C program to find the largest and smallest element in an array by using for loop C program to print the multiplication table of any integer number with multiplication range C program to print prime numbers from 1 to N using for loop C program to check input number is even or odd using if-else statement and with conditional operator C program to find the average of N numbers by using for loop
Recent Articles
  • Write a program to find all the patterns of 0(1+)0 in the given string
  • C# program to enter two numbers and find their sum
  • Write a c++ program to store information of a student using the structure with the for loop
  • Write a c program to store information of a student using the structure with the for loop
  • How to write a c++ program to find the sum of natural numbers using recursion
  • How to write a c program to find the sum of natural numbers using recursion
  • Write a python program to convert an array into zig-zag fashion using the function
  • C program to perform input/output of all basic data types
  • Write a python program to print a hollow square star pattern with diagonal using loops (for and while loop)
  • Write a c program to make a circular rotation of an array by k positions using the loops
View All Articles
  W3Codeworld

Get the latest updates

  • ABOUT US
  • About Company
  • Contact Us
  • Terms Conditions
  • Privacy Policy
  • Top Tutorials
  • PHP
  • Codeigniter
  • Laravel
  • Top Articles
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • PHP

© Copyright 2020-2021. All Rights Reserved.