Input 20 numbers in a SDA and print the reverse of all numbers
Answers
Answer:
Input 20 numbers in an SDA and print the reverse of all numbers.
Explanation:
#include <stdio.h>
void main()
{
int i,n,a[100];
printf("\n\nRead n number of values in an array and display it in reverse order:\n");
printf("------------------------------------------------------------------------\n");
printf("Input the number of elements to store in the array :");
scanf("%d",&n);
printf("Input %d number of elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&a[i]);
}
printf("\nThe values store into the array are : \n");
for(i=0;i<n;i++)
{
printf("% 5d",a[i]);
}
printf("\n\nThe values store into the array in reverse are :\n");
for(i=n-1;i>=0;i--)
{
printf("% 5d",a[i]);
}
printf("\n\n");
}
Output:-
Read n number of values in an array and display it in reverse order:
------------------------------------------------------------------------
Input the number of elements to store in the array: 3
Input 3 number of elements in the array:
element - 0: 2
element - 1: 5
element - 2: 7
element - 3: 8
element - 4: 7
element - 5: 2
element - 6: 7
element - 7: 1
element - 8: 8
element - 9: 2
element - 10: 9
element - 11: 6
element - 12: 5
element - 13: 3
element - 14: 1
element - 15: 0
element - 16: 9
element - 17: 7
element - 18: 4
element - 19: 5
The values store into the array are :
2 5 7 8 7 2 7 1 8 2 9 6 5 3 1 0 9 7 4 5
The values store into the array in reverse are :
5 4 7 9 0 1 3 5 6 9 2 8 1 7 2 7 8 7 5 2