Dealing With "for" Loop

Hi, guys If you are new to C++ and finding difficulty in dealing with for loop.
Here's a program which can help you understanding the multiple for loop concept and will also let you know how you can create a diamond in C++


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* A simple program to create Diamond */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=1;i<10;i++)               /*Upper half of diamond*/
{
for(k=13-i;k>=1;k--)
{
cout<<" ";  }
for(j=0;j<i;j++)
{
cout<<"*";
cout<<" ";
}
cout<<"\n";
}


for(i=10;i>=1;i--)              /*Lower half*/
{
for(k=14-i;k>=1;k--)
{
cout<<" ";
}
for(j=1;j<i;j++)
{
cout<<"*";
cout<<" ";
}
cout<<"\n";
}
getch();
}
Topic archived. No new replies allowed.