1. Stars Triangle in C++
Structure of the Problem Requirements
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 their 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 by a Star |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment