标题:c语言小程序,求高人指点
取消只看楼主
杨龙龙
Rank: 2
等 级:论坛游民
帖 子:17
专家分:29
注 册:2012-3-8
结帖率:100%
已结贴  问题点数:5 回复次数:0 
c语言小程序,求高人指点
口袋中有red,yellow,blue,white,black 五种颜色的球若干个,每次从口袋中先后取出3个球,问得到3种不同颜色的球的可能取法,输出每种排列的情况。

自己写的程序如下,可是总有error运行不了,求高人指点。

#include <stdio.h>
int main ()
{
    enum Color {red,yellow,blue,white,black};
    enum Color i,j,k,pri;
    int n,loop;
    n=0;
    for(i=red;i<=black;i++)
        for(j=red;j<=black;j++)
            if(i!=j)
            {
                for(k=red;k<=black;k++)
                    if((k!=i)&&(k!=j))
                    {
                        n=n+1;
                        printf("%-4d",n);
                        for(loop=1;loop<=3;loop++)
                        {
                            switch(loop)
                            {
                            case 1:pri=i;break;
                            case 2:pri=j;break;
                            case 3:pri=k;break;
                            default:break;
                            }
                            switch (pri)
                            {case red :printf("%-10s","red");break;
                            case yellow: printf("%-10s","yellow");break;
                            case blue :printf("%-10s","blue");break;
                            case white:printf("%-10s","white");break;
                            case black:printf("%-10s","black");break;

                            default:break;
                            }
                        }
                        printf("\n");
                    }
            }
            printf("\ntotal :%5d\n",n);
            return 0;
}
搜索更多相关主题的帖子: c语言 include yellow 
2012-03-11 18:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-362848-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.161784 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved