How to Make a Stars Triangle in C++

In this Problem we make a triangle with Stars . To complete this task we need a nested For Loops which have a Sequence to accomplish task and give output as a triangle of stars.

Source Code


# include<stdio.h>
# include<conio.h>
int main ()
{

 int spaces = 5;
 int stars = 1;
 
  for ( int i = 1 ; i <= 5 ; i++ )                         //This loop can executes Five times 
  {
   for ( int j = 1 ; j <= spaces ; j++ )         //This loop can executes One times 
   {
    printf(" ");         //Leave the Spaces 
   }
    for (int k = 1 ; k <= stars ; k++ )    //This loop can executes four times 
    {
     printf("*");        // Display the Star on the Screen
     printf(" ");        //Leave the Spaces from the Screeb
    }
    printf("\n");
    stars++ ;          // Increment in the Star Variable
    spaces-- ;          // Decrement in the Space Variable
 }
 
return 0;
}

Output of the Program

Triangle of Star

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment