C++ 在同一行上打印多个输出
在那里。我是自学C++的“C++ +无惧”。有一个练习涉及2个数字的GCD,要求在过程的每个步骤中打印“GCD(a,b)=>”。我能够让它工作:C++ 在同一行上打印多个输出,c++,C++,在那里。我是自学C++的“C++ +无惧”。有一个练习涉及2个数字的GCD,要求在过程的每个步骤中打印“GCD(a,b)=>”。我能够让它工作: int gcd (int a, int b); int main() { int i,j; cout << "Enter the first integer" << endl; cin >> i; cout << "Enter the second integer" &l
int gcd (int a, int b);
int main() {
int i,j;
cout << "Enter the first integer" << endl;
cin >> i;
cout << "Enter the second integer" << endl;
cin >> j;
int k = gcd(i,j);
cout << "The GCD is " << k << endl;
system("PAUSE");
return 0;
}
int gcd (int a, int b){
if(b==0){
cout << "GCF(" << a;
cout << "," << b;
cout << ") => " <<endl;
return a;
}
else {
cout << "GCF(" << a;
cout << "," << b;
cout << ") => " << endl;
return gcd(b,a%b);
}
}
intgcd(inta,intb);
int main(){
int i,j;
我不能;
库特j;
int k=总干密度(i,j);
cout您可以执行以下操作:
cout << "GCF(" << a << ',' << b << ") =>" << endl;
<代码> CUT> P>它不是C++,但是你可以使用C的打印方式,在我看来,它在这种情况下看起来更好,因为流操作符少得多,<代码>我会用<代码> STD::CUT它当然取决于你所说的“更好”。你当然可以只使用一个cout
并将输出链接到一行,如果你愿意的话。我不知道你可以用这种方式使用嵌套引号。非常感谢!我熟悉C方式。非常感谢大家的回复!
cout << "GCF(" << a << ',' << b << ") =>" << endl;
#include <cstdio>
printf("GCF(%d, %d) =>\n", a, b);