小明有5本书,要借给A、B、C这3位小朋友,若每人每次只能借1本,则可以有多少种不同的借法?
1.定义整形A、B、C;
2.写3重循环;
3.打印结果;
#include<iostream>
using namespace std;
int main()
{
int A, B, C,i = 0;
for (A = 1; A <= 5; A++) {
for (B = 1; B <= 5; B++) {
for (C = 1; C <= 5 && A != B; C++) {
if (A != C && B != C) {
cout <<"A:" << A << " " <<"B:" << B << " " <<"C:" << C << " ";
i++;
if (i % 4 == 0)cout << endl;
}
}
}
}
return 0;
}
标签:includeusing,cout,1.2,int,知多少,借书 From: https://www.cnblogs.com/hbro/p/17316129.html