How do I reverse an array in C?
How can we do reverse an array in C
Logic to print array in reverse order:
- Take the num and element of the array variable from the user.
- Take I variable for looping.
- Run the for loop from I=num-1 to I >=0 and decrement the value of I.
- print the array element that is arr[i].
- #include<stdio.h>
- int main()
- {
- int num , arr[num] , i;
- printf("Enter the size of an array:");
- scanf("%d",&num);
- for(i=0;i<num;i++)
- {
- scanf("%d",&arr[i]);
- }
- printf("Reverse of an array of the element:");
- for(i = num-1; i >= 0; i--)
- {
- printf("%d\n",arr[i]);
- }
- return 0;
- }
Comments
Post a Comment