Page 179 - C++
P. 179

OR

        int SKIPSlJM(int A[ ][3], int N, int M)

        {

        int S=0;

         for (int I = 0; 1< N; I++)

                for (int J = (I%2==0)? 0:1 ; J<M; J = J+2)

                       S = S + A [I][J];

         return S;

        }



        (b) Write a function REASSIGN() in C++, which accepts an array of integers and its size as parameters and
            divide all those array elements by 5 which are divisible by 5 and multiply other array elements by 2. (3)


        Ans.
        void REASSIGN (int Arr[ ], int Size)


        {
                for (int i=0;i<Size;i++)

                if (Arr[i]%5==0)

                        Arr[i]/=5;

               else

                        Arr[i]*=2;

        }

                                                             OR

        (b) Write a function in C++ which accepts an integer array and its size as arguments and replaces elements
            having even values with its half and elements having odd values with twice its value.            (3)

        Example : If an array of five elements initially contains the elements as 3, 4, 5, 16, 9. then the function should
        rearrange content of the array as 6, 2, 10, 8, 18

        Ans.

        void accept(int a[ ],int size)

        {

               for (int i=0; i<size; i++)

               {
   174   175   176   177   178   179   180   181   182   183   184