Computer Science, asked by AnuradhaMaji, 2 months ago

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.​

Answers

Answered by LeelaGhosh1
8

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        Description

sc                   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.

Attachments:
Similar questions