注册 登录
编程论坛 C++教室

再求助

lljojo501 发布于 2012-09-27 23:16, 338 次点击
不知道为什么两个结果不一样??????内层{}的意义是什么

#include<stdio.h>
#include<iostream.h>
#include<math.h>
main( )
{   
    char i,j,k;
    void show(char );
    for (i='X';i<='Z';i++)
        for (j='X';j<='Z'; j++)
            if (i!=j)
                for (k='X';k<='Z';k++)
                    if (i!=k&&j!=k)
                        if( i!='X'&&k!='X'&&k!='Z')
                        {printf("A--%c\tB--%c\tC--%c\n",i,j,k);
                        cout<<"A-";
                        show(i);
                        cout<<"B-";
                        show(j);
                        cout<<"C-";
                        show(k);}



        
}
void show(char p)   
{
if(p=='X')
cout<<"zhangsan\n";
if(p=='Y')
cout<<"lisi\n";
if(p=='Z')
cout<<"wangwu\n";
}


第二个#include<stdio.h>
#include<iostream.h>
#include<math.h>
main( )
{   
    char i,j,k;
    void show(char );
    for (i='X';i<='Z';i++)
        for (j='X';j<='Z'; j++)
            if (i!=j)
                for (k='X';k<='Z';k++)
                    if (i!=k&&j!=k)
                        if( i!='X'&&k!='X'&&k!='Z')
                        printf("A--%c\tB--%c\tC--%c\n",i,j,k);
                        cout<<"A-";
                        show(i);
                        cout<<"B-";
                        show(j);
                        cout<<"C-";
                        show(k);



        
}
void show(char p)   
{
if(p=='X')
cout<<"zhangsan\n";
if(p=='Y')
cout<<"lisi\n";
if(p=='Z')
cout<<"wangwu\n";
}
3 回复
#2
lz10919149992012-09-28 12:45
这是最基础的东西啊?书上都有的,翻翻书吧。
#3
lljojo5012012-09-28 18:51
难理解啊!
#4
lz10919149992012-09-28 19:01
2条语句以上就需要用{}括起来,否则就只有第一条语句有效,因为它们是一个整体。当然如果只有一条语句,那么{}不要也罢。

这些东西在书上都能找到的,以后这些基础的东西就别拿来问了。
1