Page 368 - CA_Blue( J )_Class10
P. 368

5      {

                 6          Scanner sc= new Scanner(System.in);
                 7          int ar[]=new int[5];
                 8          double avg,s=0;

                 9          int i,c=0;

                10          for(i=0;i<5;i++)
                11          {
                12              System.out.print("Enter a number : ");

                13              ar[i]=sc.nextInt();
                14          }

                15          for(i=0;i<5;i++)
                16          {

                17              if(ar[i]%2==0)
                18              {

                19                  s=s+ar[i];
                20                  c++;

                21              }
                22          }

                23          avg=s/c;
                24          System.out.println("Total  :"+s);

                25          System.out.println("Average :"+avg);
                26      }

                27  }

              You will get the following output:
              Enter a number: 3

              Enter a number: 4
              Enter a number: 2
              Enter a number: 6

              Enter a number: 7
              Total of even elements: 12.0

              Average: 4.0

              15.3.1 Multi-Dimensional Array
              An array containing two or more subscripts indicating the position of the elements in the array is known as multi-
              dimensional array. It contains values in the form of rows and columns similar to matrix. Multi-dimensional array is also
              known as double-dimensional array.



                366366  Touchpad Computer Applications-X
   363   364   365   366   367   368   369   370   371   372   373