In: Computer Science
Here's the program that prints the desired output as per the question :
Note:- As the programming environment is not mentioned I've used Java Programming language and Python for the above question, If you need this code in C, C++ please let me know in comments.
(IN Python)
print ("Enter lower and upper bounds :")
l=int(input())
u=int(input())
while l>u:
print ("Incorrect bounds please re-enter :")
print ("Enter lower and upper bounds :")
l=int(input())
u=int(input())
size=u-l+1
arr=[]
prdct=[]
a=l
for i in range(0,size):
arr.append(a)
a=a+1
for i in range (0,size):
for j in range(0,size):
prdct.append(arr[i]*arr[j])
print("Set of numbers are :")
for i in arr:
print(i,end=" ")
print("\n Products of each pair are :")
for i in prdct:
print(i,end=" ")
Output of above python program
(IN JAVA)
import java.util.*;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter Lower and Upper bounds :");
Scanner s=new Scanner(System.in);
int l=s.nextInt();
int u=s.nextInt();
while(l>u)
{System.out.println("\nIncorrect bounds please re-enter");
System.out.println("\nEnter Lower and Upper bounds :");
l=s.nextInt();
u=s.nextInt();
}
int size=u-l+1;
int []arr=new int [size];
int []prdct= new int [size*size];
int k=0;
int a=l;
for(int i=0;i<size;i++)
{
arr[i]=a;
a++;
}
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
prdct[k]=arr[i]*arr[j];
k++;
}
}
System.out.println("Set of numbers are : ");
for(int i=0;i<size;i++)
System.out.print(" "+arr[i]);
System.out.println();
System.out.println("Product of pair are :" );
for(int i=0;i<size*size;i++)
System.out.print(" "+prdct[i]);
}
}
It compiles and runs successfully and gives output as: