Pattern

23:20 0 Comments A+ a-

Problem:
Write a function, which takes starting and ending integer and print the ordered pairs on the screen:
Sample output:
Enter Starting number: 1
Enter Ending number: 5
(1,1) (1,2) (1,3) (1,4) (1,5)
(2,2) (2,3) (2,4) (2,5)
(3,3) (3,4) (3,5)
(4,4) (4,5)

(5,5)
Solution:
# include <iostream>
using namespace std;
void orderedPair(int a,int b)
{
for(int i=a;i<=b;i++)
{
for(int j=i;j<=b;j++)
{
cout<<"("<<i<<","<<j<<")"<<" ";
}
cout<<endl;
}

}
int main()
{
int startNUm;
int endNum;
cout<<"PLease enter the Starting Number : ";
cin>>startNUm;
cout<<"Please enter the Ending Number : ";
cin>>endNum;
orderedPair(startNUm,endNum);


return 0;

}