import java.util.*;
public class Splitting
{
public static void main(String[] args)
{
int n,j,i,c=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
int sum=sc.nextInt();
for (i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]+a[j]==sum)
{
c++;
System.out.println("("+a[i]+","+a[j]+")"+" = "+sum);
}
}
}
System.out.println("total pairs are"+c);
}
}
i/p: 10
1 5 3 2 4 9 6 1 7 8
12
public class Splitting
{
public static void main(String[] args)
{
int n,j,i,c=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
int sum=sc.nextInt();
for (i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]+a[j]==sum)
{
c++;
System.out.println("("+a[i]+","+a[j]+")"+" = "+sum);
}
}
}
System.out.println("total pairs are"+c);
}
}
i/p: 10
1 5 3 2 4 9 6 1 7 8
12
o/p:
(5,7) = 12
(3,9) = 12
(4,8) = 12
total pairs are3
No comments:
Post a Comment