training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

rombo2.c (769B)


      1 /* Esercizio 4.32 */ 
      2 
      3 #include <stdio.h>
      4 
      5 int main()
      6 {
      7    int i, j, k, x;
      8    int lines;
      9 
     10    printf("Numero di linee: ");
     11    scanf("%d", &lines);
     12 
     13  if (lines % 2 && lines >= 1 && lines <= 19) {
     14 
     15    for(i = 1, x = lines / 2; i <= lines; i += 2, --x) {
     16       for(j = x; j >= 1; --j) /* stampa 'x' spazi */ 
     17 	 printf(" ");
     18 
     19       for(k = i; k >= 1; --k) /* stampa 'i' asterischi */
     20          printf("*");
     21 
     22       printf("\n");
     23    }
     24 
     25    for(i = lines - 2, x = 1; i >= 1; i -= 2, ++x) { 
     26       for(j = x; j >= 1; --j) /* stampa 'x' spazi */
     27 	 printf(" ");
     28 
     29       for(k = i; k >= 1; --k) /* stampa 'i' asterischi */
     30 	 printf("*");
     31       printf("\n");
     32    } /* end of for */
     33 
     34  } /* End IF */
     35  else
     36     printf("Usare interi dispari da 1 a 19\n");
     37 
     38 
     39    return 0;
     40 } /* E0F main */
     41