/* Program which inputs two integers from user and displays specific sequence. For Example: Enter starting integer: 11 Enter ending integer: 18 (11,11)(11,12)(11,13)(11,14)(11,15)(11,16)(11,17)(11,18) (12,12)(12,13)(12,14)(12,15)(12,16)(12,17) (13,13)(13,14)(13,15)(13,16) (14,14)(14,15) */ #include<iostream> //for input/output functions and statements using namespace std; int main() { int sub = 0, num1, num2; //Declares two int variable 'num1' & 'num2' cout << "Enter Starting number: "; //Displays Message cin >> num1; //Get's 1st number cout << "Enter Ending number: "; //Displays Message cin >> num2; //Get's 2nd number cout << endl; if (num2 < num1) cout << "Invalid Input"; else for (int i = num1; i <= num1 + (num2 - num1) / 2 + 1; i++) //Outer Loop (Controls 1st digit of the order pairs) { for (int j = i; j <= num2 - sub; j++) //Inner Loop (Controls 2nd digit of the order pairs) cout << "(" << i << "," << j << ")"; //Display Order Pairs cout << endl; //Move Cursor to the next line sub++; //increments the value of 'sub' by 1 } cout << endl; //Move Cursor to the next line return 0; }
This blog is about coding in some commonly used "High Level Languages" like C, C++, Java etc. At first, I will post here basic programs written in C++ language only.
Wednesday, December 17, 2014
C++ Program which inputs two integers from user and displays a SEQUENCE
Labels:
C++ Programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment