Input 10 numbers in 1d array and reverse the original array in C
One Dimensional Array - Question 7
In this question, we will see how to input 10 numbers in a one dimensional integer array and reverse the original array and print it on the screen in C programming. To know more about one dimensional array click on the one dimensional array lesson.
Q7) Write a program in C to input 10 numbers in a one dimensional integer array and reverse the original array and print it on the screen.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int a[10], i,t;
printf("Enter 10 numbers\n");
for(i=0; i<10; i++)
{
scanf("%d",&a[i]);
}
//Reversing the array
for(i=0; i<5; i++)
{
t=a[i];
a[i]=a[9-i];
a[9-i]=t;
}
printf("\nModified array after reversal\n");
for(i=0; i<10; i++)
{
printf("%d ",a[i]);
}
return 0;
}
Output
Enter 10 numbers 18 12 5 10 15 45 38 72 64 11 Modified array after reversal 11 64 72 38 45 15 10 5 12 18