c# - how can I draw a triangle of asterisks using the while statement? -


here (not working code) , should print shape below not :

static void main(string[] args) {     int = 1;     int k = 5;     int h = 1;      while (i <= 5)     {         console.writeline("");         while (k > i)         {             console.write(" ");             k--;         }         while (h <= i)         {             console.write("**");             h++;         }         i++;     }     console.readline();  } 

screenshot

but when try same using while statement shape gets totally messed up.

any ?

you have declare k , h within loop:

static void main(string[] args) {     int = 1;     while (i <= 5)     {         int k = 5;         int h = 1;          console.writeline("");         while (k > i)         {             console.write(" ");             k--;         }         while (h <= i)         {             console.write("**");             h++;         }         i++;     }     console.readline(); } 

with current solution, after first outer loop iteration, inner loops nothing.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -