打卡2

问题描述:小明有5本新书,要借给ABC三位小朋友,若每人每次只能接1本,则可以有多少种不同的借法?

流程图:

 

伪代码:

for a<-1 to 5

for b<-1 to 5

for c<-1 to 5

if a=b=c

then continue

else output a,b,c

代码:

#include <iostream>

using namespace std;

int main()

{

int a,b,c;

for(a=1;a<=5;a++)

{

for(b=1;b<=5;b++)

{

for(c=1;c<=5;c++)

{

if((a!=b)&&(b!=c)&&(a!=c))

cout<<"A:"<<a<<" B:"<<b<<" C:"<<c<<" ";

}

}

}

return 0;

}

 

posted @ 2023-04-19 20:36  umiQa  阅读(16)  评论(0)    收藏  举报