Write a program in c that reverses the order of the elements of an array. a) Sto
ID: 3930601 • Letter: W
Question
Write a program in c that reverses the order of the elements of an array. a) Store the reversed elements in a new array b) Store the reversed elements in the same arrayWrite a program in c that reverses the order of the elements of an array. a) Store the reversed elements in a new array b) Store the reversed elements in the same array
Write a program in c that reverses the order of the elements of an array. a) Store the reversed elements in a new array b) Store the reversed elements in the same array
Explanation / Answer
#include<stdio.h>
int main() {
int arr[30], arr1[30],i, j, num, temp;
printf(" Enter no of elements : ");
scanf("%d", &num);
//Read elements in an array
for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}
j = i - 1; // j will Point to last Element
i = 0; // i will be pointing to first element
while (i < j) {
temp = arr[i];
arr[i] = arr1[j];
arr1[j] = temp;
i++; // increment i
j--; // decrement j
}
//Print out the Result of Insertion
printf(" Result after reversal : ");
for (i = 0; i < num; i++) {
printf("%d ", arr1[i]);
}
//adding reversed array to base array
for (int m=num;m=num;m++)
{
j=0;
arr[m]=arr1[j];
j++;
}
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.