Here's a C program to read and reverse an array. This can easily be done with the help of for loop. This program uses C concepts like For Loop in C, Auto Incrementing Operator ++ and Auto Decrementing Operator --.
Output of above program is
Enter the limit : 5
Enter the elements :
20 30 50 10 40
The reversed array is :
40 10 50 30 20
# include <stdio.h> # include <conio.h> void main() { int a[20], i, n ; clrscr() ; printf("Enter the limit : ") ; scanf("%d", &n) ; printf("\nEnter the elements :\n\n") ; for(i = 0 ; i < n ; i++) scanf("%d", &a[i]) ; printf("\nThe reversed array is :\n\n") ; for(i = n - 1 ; i >= 0 ; i--) printf("%d\t", a[i]) ; getch() ; }
Output of above program is
Enter the limit : 5
Enter the elements :
20 30 50 10 40
The reversed array is :
40 10 50 30 20
Explanation of above program
Here we have an array a[20] of type integer and size 20. First we ask the user to enter a limit or number of elements he wants to be in that array. After that using a for loop we populates the array up to that limit that user entered.
Now to print the values of an array in reverse order i.e. (n - 1)th value first, we simply have to use a for loop that starts at the value of i = n - 1, decrementing that value by 1 after each iteration until the value of i becomes less than 0. So the loop will run in reverse direction and hence printing the array values in reverse order.
Values of loop variable will be like this - (n -1), (n -2), (n -3),........, 3, 2, 1, 0.
Thanks
can you pls provide a program that has for loop,while,switch statement and if else.,plss.,
can you pls provide a program that has for loop,while,switch statement and if else.,plss.,
Hi Tanmay,
Zoooooooom! That’s how speedy and easy this read was! Looking forward to more of such powerful content on Program to Read and Reverse an Array in C!
One aspect that affects the efficiency of a hashing implementation is the hash function itself. It should ideally distribute data randomly throughout the entire hash table, to reduce the likelihood of collisions. Collisions occur when two different keys have the same hash value.
There are two ways to resolve this problem. In open addressing, the collision is resolved by the choosing of another position in the hash table for the element inserted later.
Please keep providing such valuable information.
Obrigado,
John
Not giving the correct output . Printing default values🤭