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

我是新人,请多指点!

javatom 发布于 2010-05-26 17:03, 388 次点击
#include "iostream.h"
void main()
{
    for(int x=0;x<=4;x++)
    {
        for(int y=7;y>x;y--)
            cout << " ";
        for(int z=1;z<=2*x+1;z++)
            cout <<"*";
        cout<<endl;
    }

   for(x=0;x<=4;x++)
   {
       for(int y=0;y<=x+3;y++)
           cout<< " ";
       for(int z=7;z>=2*x+1;z--)
           cout<<"*";
       cout<<endl;
   }
}
有没有这样编行吗?为什么在下面的for里还要声明一次y,z?
2 回复
#2
code_guy2010-05-26 19:40
因为你上面的Y Z在循环完后的值  就不是7和4了  所以要从新赋值
#3
lscalin2010-05-26 20:22
我认为如果上下变量没有啥关联的,最好不要取相同的名字,容易造成误解,
1