i am creating a star pyramid pattern in c, everything is fine but the star "*" is increasing by 2 where it should be increase by 1. here is my code:
#include<stdio.h>
int main()
{
int i,j,k,n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
for(j=1; j<=n-i; j++)
printf(" ");
for(k=1; k<=(2*i-1); k++) // here k should increase by 1 but it is increasing by 2
printf("*");
printf("\n");
}
return 0;
}
Output is:
Enter the number of rows: 5
*
***
*****
*******
*********
as you can see that star is increasing by 2. i don't know why.
Aucun commentaire:
Enregistrer un commentaire