0% found this document useful (0 votes)
31 views1 page

Program Code: Output

This C++ program uses nested for loops to print out a triangle of stars. It first prints the top half of the triangle by decreasing the amount of spaces and increasing the number of stars on each line. It then prints the bottom half by increasing the spaces and decreasing the stars in a symmetrical pattern to complete the triangle shape. The program takes in no user input and simply runs the nested for loops to output the triangle pattern to the console.

Uploaded by

cris
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)
31 views1 page

Program Code: Output

This C++ program uses nested for loops to print out a triangle of stars. It first prints the top half of the triangle by decreasing the amount of spaces and increasing the number of stars on each line. It then prints the bottom half by increasing the spaces and decreasing the stars in a symmetrical pattern to complete the triangle shape. The program takes in no user input and simply runs the nested for loops to output the triangle pattern to the console.

Uploaded by

cris
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/ 1

Program Code:

Output:
#include<iostream>
*
using namespace std; * *
* * *
int main() * *
{ *
int n, c, k, space = 1;
n=3;

space = n-1;
for(k = 1; k<=n; k++)
{
for (c = 1; c<=space; c++)
cout<<" ";
space--;
for (c = 1; c<= 2*k-1; c++)
cout<<"*";
cout<<"\n";
}
space = 1;
for(k = 1; k<= n - 1; k++)
{
for (c = 1; c<= space; c++)
cout<<" ";
space++;
for (c = 1 ; c<= 2*(n-k)-1; c++)
cout<<"*";
cout<<"\n";
}
return 0;
}

You might also like