标题:编译无错误!无警告!为什么一运行就完蛋了??请高手看看
只看楼主
zd1505675319
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:139
专家分:178
注 册:2011-11-4
结帖率:100%
 问题点数:0 回复次数:11 
编译无错误!无警告!为什么一运行就完蛋了??请高手看看
#include<stdio.h>                    //程序的目的是 每次从5个颜色中取出3种 有多少种取法 然后输出排列情况
int main()
{    enum Color{red,yellow,blue,white,black};
    enum Cclor 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;
}
搜索更多相关主题的帖子: 众人 include 安全感 
2012-02-12 15:28
ljl123970
Rank: 2
等 级:论坛游民
帖 子:31
专家分:42
注 册:2012-1-30
得分:0 
倒数第十三行  case black: printf("%-10s",black); break; black需要双引号吧

我用的VC6.0没enum库
稍微改了下
如下:
程序代码:
#include<stdio.h>                    //程序的目的是 每次从5个颜色中取出3种 有多少种取法 然后输出排列情况
int main()
{    int a[5] = {1, 2, 3, 4,5};
    int Cclor,i,j,k,pri;
    int n,loop;
    n=0;
    for(i=1;i<=5;i++)
    {    for(j=1;j<=5;j++)
        {
            if(i!=j)
            {    for(k=1;k<=5;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 1: printf("%-10s","red"); break;
                                case 2: printf("%-10s","yellow"); break;
                                case 3: printf("%-10s","blue"); break;
                                case 4: printf("%-10s","white"); break;
                                case 5: printf("%-10s","black"); break;
                                default: break;
                            }
                        }
                        printf("\n");
                    }
                }
            }
        }
    }
    printf("\ntotal:%5d\n",n);
    return 0;
}



2012-02-12 17:01
ljl123970
Rank: 2
等 级:论坛游民
帖 子:31
专家分:42
注 册:2012-1-30
得分:0 
楼主看下 行不
2012-02-12 17:02
yxiangyxiang
Rank: 3Rank: 3
来 自:/\/\/\/\/
等 级:论坛游侠
帖 子:130
专家分:186
注 册:2012-1-29
得分:0 
运行了一下好像没问题 给你个
程序代码:
#include <stdio.h>

int main( void )
{
    char    *color[5]={ "red", "yellow", "blue", "whie", "black"};
    int    i, j, k, n=0;
    for( i=0; i<5; i++ )
        for( j=0; j<5; j++ )
            if( i!=j )
                for( k=0; k<5; k++ )
                    if( k!=i && k!=j )
                    {
                        n++;
                        printf("%4d%10s%10s%10s\n", n, color[i], color[j], color[k]);
                    }
    return 0;
}


[ 本帖最后由 yxiangyxiang 于 2012-2-12 17:15 编辑 ]
2012-02-12 17:07
ljl123970
Rank: 2
等 级:论坛游民
帖 子:31
专家分:42
注 册:2012-1-30
得分:0 
楼上的 代码好看
2012-02-13 09:43
BianChengNan
Rank: 8Rank: 8
等 级:贵宾
威 望:13
帖 子:302
专家分:972
注 册:2011-11-30
得分:0 
以下是引用zd1505675319在2012-2-12 15:28:42的发言:

#include                    //程序的目的是 每次从5个颜色中取出3种 有多少种取法 然后输出排列情况
int main()
{    enum Color{red,yellow,blue,white,black};
    enum Cclor 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;
}
这个貌似在大学课本上看过

我的群:149544757 C/C++/Assembly 喜欢交流的朋友进,进群请写消息
2012-02-13 13:48
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
得分:0 
打印C(5,3)
程序代码:
#include <stdio.h>
int data[100] = {5,4,3,2,1};
bool foot[100] = {0};
int cool = 0;
void com(int n,int k,int mem[],int depth,int begin,int pos)
{
    int i,j;
    if(k == depth)
    {
        for(i = 0;i<k;i++)
            printf("%d ",mem[i]);
        cool++;
        printf("\n");
        return ;
    }
    for(i = pos;i<n;i++)
    {
        if(!foot[i])
        {
            foot[i] = true;
            mem[begin] = data[i];
            com(n,k,mem,depth+1,begin+1,i+1);
            foot[i] = false;
        }
    }
}
int main()
{
    int mem[100] = {0};
    com(5,3,mem,0,0,0);
    return 0;
}

 
 

                                         
===========深入<----------------->浅出============
2012-02-13 14:53
lynsen
Rank: 2
等 级:论坛游民
帖 子:31
专家分:52
注 册:2011-9-4
得分:0 
代码太多嵌套了,不想看
2012-02-13 15:16
zd1505675319
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:139
专家分:178
注 册:2011-11-4
得分:0 
谢谢各位
2012-02-13 15:31
小赵q1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:492
专家分:777
注 册:2011-8-26
得分:0 
楼主的代码看起来很有型;
2012-02-13 18:51



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




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

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