Kindly Make me understand this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Kindly Make me understand this code

#include <stdio.h> int main() { int i,j,n; printf("Input number of rows for this pattern :"); scanf("%d",&n); for(i=0;i<=n;i++) { for(j=1;j<=n-i;j++) printf(" "); for(j=1;j<=2*i-1;j++) printf("*"); printf("\n"); } }

21st Aug 2022, 1:04 PM
Md Motasim Billah
Md Motasim Billah - avatar
1 Answer
+ 1
First loop runs from value I=0, n including,.. repeating.. : 2nd prints 1 to n-i spaces, followed by 1 to 2*i-1 "*" like: N spaces 1 star ; //( 2*1-1) N-1 spaces 3 stars ; // 2*2-1 N-2 spaces 5 stars // 2*3-1 ... .. Until N-N spaces Hope it helps...
21st Aug 2022, 2:08 PM
Jayakrishna 🇮🇳