
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program for Program for array rotation?
Write a C program to left rotate an array by n position. How to rotate left rotate an array n times in C programming. Logic to rotate an array to left by n position in C program.
Input: arr[]=1 2 3 4 5 6 7 8 9 10 N=3 Output: 4 5 6 7 8 9 10 1 2 3
Explanation
Read elements in an array say arr.
Read number of times to rotate in some variable say N.
Left Rotate the given array by 1 for N times. In real left rotation is shifting of array elements to one position left and copying first element to last.
Example
#include <iostream> using namespace std; int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int i, N, len, j; N=3; len=10; int temp=0; for (i = 0; i < N; i++) { int x = arr[0]; for (j = 0; j < len; j++) { temp=arr[j]; arr[j] = arr[j + 1]; arr[j+1]=temp; } arr[len - 1] = x; } for (i = 0; i < len; i++) { cout<< arr[i]<<"\t"; } }
- Related Articles
- C Program for Reversal algorithm for array rotation
- Python Program for array rotation
- Java Program for array rotation
- Golang Program For Array Rotation
- Java Program for Reversal algorithm for array rotation
- Python Program for Reversal algorithm for array rotation
- Reversal Algorithm for Array Rotation using C++
- Block swap algorithm for array rotation in C++
- C Program for product of array
- C++ program for multiplication of array elements
- Reversal Algorithm for Right Rotation of an Array using C++
- C++ Program for QuickSort?
- Program for EMI Calculator in C program
- C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling
- Java program for Multiplication of Array elements.

Advertisements