Page 74 - C++
P. 74

(a)    Write a user-defined function AddEnd4(int  A[][4],int R,int C) in C++ to      (2)
                      Ans.  find and display the sum of all the values, which are ending with 4 (i.e.,
                             unit place is 4).
                             For example if the content of array is:
                                                      24  16  14
                                                      19  5    4
                             The output should be 42

                                                                OR

                             Write a user defined function in C++ to find the sum of both left and right
                             diagonal elements from a two dimensional array.

                             void AddEnd4(int A[ ][4], int R, int C)
                             {
                                      int I,J,sum=0;
                                      for(I=0;I<R;I++)
                                      {
                                              for(J=0;J<C;J++)
                                if(A[I][J]%10 ==4)
                                                   sum=sum+A[I][J];
                                      }
                                     cout<<sum;
                             }

                                                                OR
                             void Diagsumboth(int A[][4], int n)
                             {
                             int sumLt=0,sumRt=0;
                             for(int i=0;i<n;i++)
                             {
                             sumLt+=A[i][i];
                             else
                             sumRt+=A[n-1-i][i];
                             }
                             cout<<”sum of left diagonal”<<sumlt<<endl;
                             cout<<”sum of right diagonal”<<sumRt<<endl;
                             }

                             (½ Mark for correct loops)
                             (½ Mark for correct checking values ending with 4)
                             ( ½ Mark for  finding sum of values)
                             ( ½ Mark for displaying the sum )

                                                                OR
                             (1/2 Mark for correct loop)
                             (1/2 Mark each for calculating sum of left or right diagonals)
                             (1/2 Mark for displaying)


                                                             10
   69   70   71   72   73   74   75   76   77   78   79