Write a program in c that reverses the order of the elements

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

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

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

Solution

#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 \\t\", arr1[i]);

   }

//adding reversed array to base array

for (int m=num;m=num;m++)

{

j=0;

arr[m]=arr1[j];

j++;

}

   return (0);

}

 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 s
 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 s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site