main1.cpp
来自「C++ Primer(第三版)的随书源代码」· C++ 代码 · 共 47 行
CPP
47 行
// Section 7.1
// $ CC gcd.C main1.C
#include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
// definition in gcd.C
int gcd( int, int );
inline int abs( int iobj ) {
return( iobj < 0 ? -iobj : iobj );
}
inline int min( int v1,int v2 ) {
return( v1 < v2 ? v1 : v2 );
}
int main()
{
// get values from standard input
cout << "Enter first value: ";
int i;
cin >> i;
if ( !cin ) {
cerr << "!? Oops: input error - Bailing out!\n";
return -1;
}
cout << "Enter second value: ";
int j;
cin >> j;
if ( !cin ) {
cerr << "!? Oops: input error - Bailing out!\n";
return -2;
}
cout << "\nmin: " << min( i, j ) << endl;
i = abs( i );
j = abs( j );
cout << "gcd: " << gcd( i, j ) << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?