| 1. |
wap to input 10 numbers in two different array then calculate the total by adding each cell of both array and then store it in the third array. |
|
Answer» Required Program (In java) - import java.util.Scanner; //Scanner CLASS is imported for input. public class SumArray{ public static void main(String args[]){ //main method Scanner sc = new Scanner(System.in); //Scanner class object is created. int a[] = new int[10]; //First array. int b[] = new int[10]; //Second array. int C[] = new int[10]; //Array to store sum of corresponding elements. for(int i =0;i<10;i++){ //Loop to accept the terms of both arrays. System.out.println("Enter the #"+(i+1)+" no. for 1st array -"); a[i] = sc.nextInt(); System.out.println("Enter the #"+(i+1)+" no. for 2nd array -"); b[i]= sc.nextInt(); } //Now for the sum of corresponding elements. for(int j = 0; j<10;j++){ c[j] = a[j] + b[j] ; } System.out.println("The sum of corresponding elements is -"); for(int k = 0; k<10;k++){ System.out.print(c[k] + " , "); } } } Variable Description -Variable Type Descriptionsc Object Scanner class object a int array 1st array b int array 2nd array c int array 3rd array to store sum of corresponding elements i int Loop variable for ACCEPTING terms. j int Loop variable for storing sum of terms in c[] . k int Loop variable for PRINTING the array c[] . OUTPUT -=> Refer to the attachment for output. |
|