Tuesday, 15 April 2014

c - Drawing a triangle using a for loop -



c - Drawing a triangle using a for loop -

here's problem. using characters * , +you need form rectangular image width m , height n (m < n) depicts right isosceles triangle character + within rectangle made of characters * (view examples). each m , n read standard input programme should output right image. attention: not print unnecessary empty spaces or new line characters. note: right solution of problem without usage of arrays/matrices since there no limit on m , n. clearance: triangle formed 1 character + @ origin of first row, 2 @ origin of sec row,... m characters + @ origin of m-th row. here's illustration of should input 3 , 4 http://prntscr.com/53xv5s

#include <stdio.h> int main () { int m, n, i, j; scanf ("%d %d", &m, &n); (i=0; i<m; i++) { printf ("+"); (j=n-1; j>0; j--) { printf ("*"); } printf ("\n"); } homecoming 0; }

any help on how prepare it? far http://prntscr.com/53xvq2

try:

#include <stdio.h> int main () { int m, n, i, j; scanf ("%d %d", &m, &n); (i=0; i<m; i++) { (j=0; j<n; j++) { if(j <= i) printf ("+"); else printf ("*"); } printf ("\n"); } homecoming 0; }

this way print n chars , n lines every line start +'s , end *

c loops for-loop

No comments:

Post a Comment