Skip to content

Instantly share code, notes, and snippets.

@Rafi993
Created Jul 1, 2017
Embed
What would you like to do?
null created by Rafi993 - https://repl.it/JJd8/0
/*C program that declares an array A and inputs n integer values in A.
Then the contents of array A is copied to another array B in reversed order.
Finally print the elements of array B*/
#include<stdio.h>
int main()
{
int n, reverse, i ;
int A[100], B[100] ;
printf("Input the size of array A: ") ;
scanf("%d", &n ) ;
printf("Input the values of A: ") ;
for( i = 0 ; i<n ; i++ )
scanf("%d ", &A[i] ) ;
for(i = n-1 , reverse = 0 ; i>= 0 ; i--, reverse++)
B[reverse] = A[i] ;
for(i = 0 ; i<n ; i++ )
A[i] = B[i];
printf("Array B: ") ;
for(i=0 ; i<n ; i++ )
printf("%d ", A[i] ) ;
return 0 ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment