# Coding question

Given the age of 10 couples(husband and wife), print Number of years of age difference for all the 10 people Input Specification First 10 inputs contain the ages of all husbands And the next 10 are the ages of all wives Output Specification Output should be exactly 10 lines giving the number of years of the age difference between them. Note: output is a positive integer Sample Input 50 40 53 24 78 99 63 22 55 15 43 39 55 24 56 89 60 18 56 25 Sample Output 7 1 2 0 22 10 3 4 1 10

#### naina

• May 6th, 2015

```Code#include<stdio.h>

void main()
{
int arr[10] = {40,54,58,32,64,48,23,30,28,60};
int m, n= 10, i,diff=0;
m=n/2;
for(i=0;i<n/2;i++)
{
diff = arr[i]- arr[m];
printf("%d
",abs(diff));
m++;
}
}```

#### mcb

• Sep 10th, 2015

This answer is wrong on many levels...
1) No input , just a set array of ages (not matching question by the way)
2) only 10 people, not 20 husbands and wives.
3) need to use /n in printf not an actual New Line.

#### amrendra

• Oct 6th, 2015

```Codepublic static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> maleages = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
int age = sc.nextInt();
}
ArrayList<Integer> femaleages = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
int age = sc.nextInt();
}
Iterator<Integer> it = maleages.iterator();
int i = 0;
while (it.hasNext()) {
System.out.print(it.next() - femaleages.get(i++)+", ");
}
}```

#### Ashwini

• Jun 1st, 2016

```Codeimport java.util.*;

class Test{

public static void main(String []args){

Scanner sc=new Scanner(System.in);
int []h=new int[10];
int []w=new int[10];
int []a=new int[10];

for(int i=0;i<10;i++)
{
h[i]=sc.nextInt();
}

for(int i=0;i<10;i++)
{
w[i]=sc.nextInt();
}

for(int i=0;i<10;i++)
{
a[i]=h[i]-w[i];
}

for(int i=0;i<10;i++)
{
if(a[i]<0)
a[i]=a[i]*-1;
System.out.println(a[i]);
}
}
}```

#### leela

• Jun 1st, 2016

By giving array the size 10 I am getting ArrayIndexOutOfBoundsException what should I do now