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; }
0 comments:
Post a Comment