0% found this document useful (0 votes)
26 views

Source Code 1

The document contains two source code examples that use nested for loops to print out patterns of asterisks ("*") and spaces. The first code prints a triangle pattern where the number of asterisks increases on each line. The second code improves on this by adding asterisks on the edges of each line to create a diamond shape pattern. Both programs use nested for loops and if statements to control where asterisks and spaces are printed on each line of output.

Uploaded by

Sidra Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Source Code 1

The document contains two source code examples that use nested for loops to print out patterns of asterisks ("*") and spaces. The first code prints a triangle pattern where the number of asterisks increases on each line. The second code improves on this by adding asterisks on the edges of each line to create a diamond shape pattern. Both programs use nested for loops and if statements to control where asterisks and spaces are printed on each line of output.

Uploaded by

Sidra Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SOURCE CODE 1:

#include<iostream>
using namespace std;
int main()
{
int i, j, k;

for (i = 1; i <= 10; i++)


{
for (j = i; j <= 10-1; j++)
cout << " ";
for (k = 1; k <= 2 * i - 1; k++)

cout << "*";

cout << endl;

}
for (int a = 9; a >=1; a--)
{
for (int b = a; b <=9; b++)
cout << " ";
for (int c = 1; c <= 2*a-1; c++)
if (c == 2 * a - 1 ||c==a)
cout << "*";
else
cout << " ";
cout << endl;
}
system("pause");
return 0;
}

SOURCE CODE 2:

#include<iostream>
using namespace std;
int main()
{
int i, j, k;
for (i = 1; i <= 10; i++)
{
for (j = i; j <= 10 - 1; j++)
cout << " ";
for (k = 1; k <= 2 * i - 1; k++)
if (k == 1 || k == 2 * i - 1 || k == i||i==10)
cout << "*";
else
cout << " ";
cout << endl;

}
for (i = 9; i >= 1; i--)
{
for (j = i; j <= 9; j++)
cout << " ";
for (k = 1; k <= 2 * i - 1; k++)
if (k==1||k == 2 * i - 1 || k == i)
cout << "*";
else
cout << " ";
cout << endl;
}
system("pause");
return 0;
}

You might also like