Program : Print this Right angled Pyramid in C using Nested Loops
* * * * * * * * * * * * * * * * * * * * *
Live Example : Program
#include<stdio.h> #include<conio.h> main() { int i,j,lines; char ch = '*'; clrscr(); printf("Enter number of lines : "); scanf("%d",&lines); for(i=0;i <=lines;i++) { printf("\n"); for (j=0;j < i;j++) printf("%c",ch); } getch(); }
Explanation of Above Code :
Accept the total number of lines to be printed.
printf("Enter number of lines : "); scanf("%d",&lines);
Now we are using nested loop to print the pyramid. First for loop is used to print the star on the line. Second loop will be used to identify the total number of stars to be printed on the screen.
for(i=0;i <=lines;i++) { printf("n"); for (j=0;j < i;j++) printf("%c",ch); }
No comments:
Post a Comment