#include <stdio.h> #include <stdlib.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) { case1: pri=i;break; case2: pri=j;break; case3: 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; }哪里错了
时间: 2024-02-10 09:09:25 浏览: 108
代码中的问题是在第23行,case1应该改为case 1,因为case后面的值应该是一个整数,而不是一个标识符。同样的问题也存在于case2和case3中。修改后的代码如下:
```
#include <stdio.h>
#include <stdlib.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;
}
```
阅读全文