编程论坛
注册
登录
编程论坛
→
C++教室
<新手求助>如何打印一个菱形?
jackface
发布于 2009-09-11 00:59, 707 次点击
同上,最好能详细讲讲内外循环的关联.
6 回复
#2
newCpp
2009-09-11 10:42
实心的好弄!!
#3
newCpp
2009-09-11 10:45
#include<iostream>
using namespace std;
int main()
{
for(int a=0;a<=10;a++)
{
for(int b=0;b<=10-a;b++)
cout<<" ";
for(int c=0;c<=a;c++)
cout<<".";
for(int j=1;j<=a;j++)
cout<<".";
cout<<endl;
}
for(int d=1;d<=10;d++)
{
for(int h=0;h<=d;h++)
cout<<" ";
for(int j=0;j<=10-d;j++)
cout<<".";
for(int k=1;k<=10-d;k++)
cout<<".";
cout<<endl;
}
}
你看看是不是这玩意,以前练习时写的,直接复制来的
呵呵,看一下吧
#4
jackface
2009-09-11 21:35
有没有人可以改进一下,第一行 *
第二行 **
第三行 ***
第四行*****
#5
newCpp
2009-09-12 07:11
程序代码:
#include<iostream>
using namespace std;
int main()
{
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10-i;j++)
cout<<" ";
for(int h=1;h<=(i*2)-1;h++)
cout<<"*";
cout<<endl;
}
}
这个是正的三角形
看一下下吧!
#6
newCpp
2009-09-12 07:18
#include<iostream>
using namespace std;
int main()
{
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10-i;j++)
cout<<" ";
for(int h=1;h<=i;h++)
cout<<"*";
cout<<endl;
}
}
这个是
*
**
***
****
这样的,
上面那程序是
*
***
*****
*******
这样的自己选择一下吧
#7
newCpp
2009-09-12 07:22
这玩意写的原理基本上差不多
就是输出*号的地方改变了一下下!!
1