Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************/
- /** 20150312 Exam 02 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2015/03/12 am.11:45 **/
- /***************************************/
- #include <iostream> //Basic C++ I/O stream
- #include <vector>
- using namespace std;
- int main(int argc, char const argv[]){
- int nData = 0;
- cin >> nData;
- /* Make a vector with integer type. Have 100 element, and set the value be [-1]
- If just want to make a vector:
- vector <type> [VectorName](Number of Element);
- Or your want to set the value to vector at first:
- vector <type> [VectorName](Number of Element, Value); */
- vector <int> ivector(100, -1);
- for(int i = 0; i < nData; i++){
- cin >> ivector[i * 1 + 1];
- cin >> ivector[i * 2 + 1];
- cout << "Your number:\n\t" << \
- "A = " << ivector[i * 1 + 1] << ", " << "B = " << ivector[i * 2 + 1] << endl;
- if(ivector[i * 1 + 1] == ivector[i * 2 + 1])
- cout << "G.C.D. is " << ivector[i * 1 + 1] << "." << endl << endl;
- else
- for(int j = ((ivector[i * 1 + 1] > ivector[i * 2 + 1]) ? ivector[i * 2 + 1] : ivector[i * 1 + 1]); j > 0; j--)
- if((ivector[i * 1 + 1] % j == 0) && (ivector[i * 2 + 1] % j == 0)){
- //Greatest Common Divisor(G.C.D.)
- cout << "G.C.D. is " << j << "." << endl << endl;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment