Write a function that reverses the contents of an array of d

Write a function that reverses the contents of an array of double and test it in a simple program.

GIVEN CODE:

#include <stdio.h>
#include <stdlib.h>


void PrintArray(int *a, int size)
{
int i;

for (i = 0; i < size; i++)
printf(\"%d\\t\", *(a+i));

printf(\"\ \");   
}

int main()
{
int *pa;
int size;
int i, j;
int temp;

printf(\"Data size: \");
scanf(\"%d\", &size);

if (size < 1)
return -1;
  
  
pa = (int*) malloc( size * sizeof(int));
if (pa == NULL){
printf(\"\ Error \ \");
return -2;
}
for (i = 0; i < size; i++)
scanf(\"%d\", (pa + i));

printf(\"\ Array:\ \");
PrintArray(pa, size);

// Reverses the Array Here


printf(\"\ New Array\ \");
PrintArray(pa, size);   
free(pa);

return 0;

}

Solution

#include <stdio.h>
#include <stdlib.h>


void PrintArray(int *a, int size)
{
   int i;

   for (i = 0; i < size; i++)
      printf(\"%d\\t\", *(a+i));

   printf(\"\ \");
}

int main()
{
   int   *pa,*z;
   int   size;
   int   i, j;
   int   temp;

   printf(\"Data size: \");
   scanf(\"%d\", &size);

   if (size < 1)
      return -1;
    
    
   pa = (int*) malloc( size * sizeof(int));
   if (pa == NULL){
      printf(\"\ Error \ \");
      return -2;
   }
   for (i = 0; i < size; i++)
      scanf(\"%d\", (pa + i));

   printf(\"\ Array:\ \");
   PrintArray(pa, size);

   // Reverses the Array Here
     z = (int*) malloc( size * sizeof(int));
   for(i=1;i<=size;i++)
   {
      z[size-i]=pa[i-1];
             
    }
    pa=z;
   printf(\"\ New Array\ \");
   PrintArray(pa, size);
   free(pa);

   return 0;

}

Write a function that reverses the contents of an array of double and test it in a simple program. GIVEN CODE: #include <stdio.h> #include <stdlib.h>
Write a function that reverses the contents of an array of double and test it in a simple program. GIVEN CODE: #include <stdio.h> #include <stdlib.h>

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site