Chinaunix首页 | 论坛 | 博客
  • 博客访问: 845556
  • 博文数量: 321
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 936
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-23 11:25
文章分类

全部博文(321)

文章存档

2017年(1)

2016年(10)

2015年(61)

2014年(187)

2013年(62)

分类: C/C++

2014-06-24 12:06:01

原文地址:C语言实例50:枚举类型 作者:hnrainll

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    enum color {blue, red, yellow, purple, black};
    enum color i, j, k, pri;
    int n, loop;
    n = 0;

    for(i = blue; i <= black; i++)
        for(j = blue; j <= black; j++)
        if(i != j){
        for(k = blue; k <= black; k++)
            if((k != i) && (k != j)){
            n++;
            printf("%-6d", 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 blue: printf("%-10s", "blue");
                    break;
                    case red: printf("%-10s","red");
                    break;
                    case yellow: printf("%-10s", "yellow");
                    break;
                    case purple: printf("%-10s", "purple");
                    break;
                    case black: printf("%-10s","black");
                    break;

                    default:break;
                }
            }
            printf("\n");
        }

    }
    printf("total: %5d\n", n);
    system("pause");
    return 0;
}


阅读(369) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~