Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C Program to Reverse an Array
๐ C Program to Reverse an Array
#include<stdio.h>
int main()
{
int num, a[100];
printf("Enter size of the array:\n");
scanf("%d", &num);
if(num <= 0)
{
printf("!invalid Array Size:\n");
return 1;
}
printf("Enter %d elements:\n", num);
for(int i = 0; i < num; i++)
{
scanf("%d", &a[i]);
}
printf("\nBefore reverse:\n");
for(int i = 0; i < num; i++)
{
printf("%d ", a[i]);
}
printf("\nAfter reverse:\n");
for(int i = num - 1; i >= 0; i--)
{
printf("%d ", a[i]);
}
}
๐ Explanation:
This program takes an array of integers from the user, displays the original array, and then prints the elements in reverse order. It uses a loop to first store the input values, and then another loop from the end of the array to the beginning for reverse display.
๐ก Sample Output:
Enter size of the array: 5 Enter 5 elements: 10 20 30 40 50 Before reverse: 10 20 30 40 50 After reverse: 50 40 30 20 10
๐ Keywords:
Reverse array in C, C program for reverse, loop reverse logic, array operations in C, beginner array program
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment