问一个关于枚举
最近看到这样一个关于水果拼盘的另解:现有苹果,橘子,香蕉,菠萝,梨5种水果用来做水果拼盘,每个水果拼盘一定有三个水果,且这3个水果的种类不同,问可以制作多少个水果拼盘:
#include<stdio.h>
void main()
{
enum fruit {apple,orange,banana,pineapple,pear}; //定义枚举结构
enum fruit x,y,z,pri; //定义枚举变量
int n=0,loop;
for(x=apple;x<=pear;x++)
for(y=apple;y<=pear;x++)
if(x!=y){
for(z=apple;z<=pear;z++)
if((z!=x)&&(z!=y)){
n=n+1;
printf("\n%-4d",n);
for(loop=1;loop<=3;loop++)
{
switch(loop){
case 1:
pri=x;
break;
case 2:
pri=y;
break;
case 3:
pri=z;
break;
default :break;
}
switch(pri){
case apple:
printf("%-9s","apple");
break;
case orange:
printf("%-9s","orange");
break;
case pineapple:
printf("%-9s","pineapple");
break;
case pear:
printf("%-9s","pear");
break;
default:break;
}
}
}
}
}
复杂了点》但在Vc下运行有错误?该怎么改呢?