Answers

2016-07-12T21:52:37+05:30

This Is a Certified Answer

×
Certified answers contain reliable, trustworthy information vouched for by a hand-picked team of experts. Brainly has millions of high quality answers, all of them carefully moderated by our most trusted community members, but certified answers are the finest of the finest.
// swap alternate numbers in an array . so 1st and 3rd.  
// 2nd and 4 are interchanged. again
//  5th and 7th are interchanged. so on....

include files

void main()  {   
    int data[100], i, n, temp;

     cin >> n;
     for ( i = 0; i<n ; i++)   {       cin >> data[i];   }
     for (i = 0 ;  i < =  n - 3 ; i += 2) {    //operate on 4 numbers at a time.        
                temp=data[i];   data[i] = data[i+2];   data[i+2] = temp;   i += 2 ;
               if (i < n - 1) {
                   temp = data[i-1] ;   data[i-1] = data[i+1] ;  data[i+1] = temp ;
               }
      }

       for (i = 0; i < n; i++)
              cout << data[i];

}
1 5 1