Practice

Element Swap



What is the exact out of the following program?  Show your intermediate work.

 // Element Swap
 //
 #include <stdio.h>
 #define D 6
 #define I {2, 3, 5, 1, 6, 4}
 void s(int a[], int i, int n);

 int main(void)
 {
         int i, d[D] = I;

         for(i = 0; i < D; i++)
                 s(d, i, D);

         for(i = D - 1; i >= 0; i--)
                 printf("%d ", d[i]);
         printf("Boom!\n");

         return 0;
 }

 void s(int a[], int i, int n)
 {
         int x;

         n /= 2;
         x = a[i];
         a[i] = a[n];
         a[n] = x;
 }
  Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site