C Program to Left Rotate Array Items

C Program to Left Rotate Array Items

Write a C program to left rotate array items for a given number of times using a for loop. This C example allows the user to enter the number of times the array has to left rotate, array size, and array elements. #include<stdio.h> void PrintArray(int a[], int Size) { for(int i = 0; i < … Read more

C Program to Sort an Array using a Pointer

C Program to Sort an Array using a Pointer

Write a C program to sort an array using a pointer. This c example passes the pointer to the SortArray function and uses the temp variable inside the for loop to sort the array in ascending order. #include <stdio.h> void SortArray(int Size, int* parr) { int i, j, temp; for (i = 0; i < … Read more

C Program to Find the Second Smallest Element in an Array

C Program to Find the Second Smallest Element in an Array

Write a C program to find the second smallest element in an array using for loop. In this c example, the if statement checks whether array items are smaller than the smallest variable and stores the second smallest array element. #include <stdio.h> #include <limits.h> int main() { int i, Size; int smallest, secSmallest; printf(“\nEnter Second … Read more

C Program to Print 2D Array Elements

C Program to Print 2D Array Elements

Write a C program to print 2D array elements or two-dimensional array items using for loop. In this c example, the first for loop iterates rows, and the second loop iterates columns. Within the C for loop, we print the 2D array elements, and we insert a new line (printf(“\n”)) for each row iteration. #include<stdio.h> … Read more

C Program to Find Array Elements Greater than Average

C Program to Find Array Elements Greater than Average

Write a c program to find array elements greater than average using for loop. In this c example, first, we find the sum and average of array elements. Next, we used the if statement (if(arr[i] > arrAvg)) checks whether each array element is greater than average. If True, that array element will print. #include <stdio.h> … Read more

C program to Calculate Average of an Array

C program to Calculate Average of an Array 2

Write a C program to calculate average of an array using for loop. In this c example, the for loop iterate all array elements and calculate the sum. Next, we calculate the average by dividing the sum with array size. #include <stdio.h> int main() { int Size, i, sum = 0; float avg = 0; … Read more

C Program to Right Rotate Array Elements

C Program to Right Rotate Array Elements

Write a C program to right rotate array elements for a given number of times using a for loop. This C example allows the user to enter the array size, array items, and the number of times the array has to rotate towards the right side. Next, we used nested for loop to shift the … Read more

C Program to Print the Kth Element in an Array

C Program to Print the Kth Element in an Array

Write a C program to print the Kth element in an array using a for loop. #include <stdio.h> int main() { int Size, i, k; printf(“Please Enter the Array size = “); scanf(“%d”, &Size); int arr[Size]; printf(“Enter the Array %d elements : “, Size); for (i = 0; i < Size; i++) { scanf(“%d”, &arr[i]); … Read more

C Program to Increment All Elements of an Array by One

C Program to Increment All Elements of an Array by One

Write a C program to increment all elements of an array by one using for loop. In this C example, we incremented each array element by one within the for loop that iterates array items. #include <stdio.h> int main() { int Size, i; printf(“Please Enter the Array size = “); scanf(“%d”, &Size); int arr[Size]; printf(“Enter … Read more