HTMLify

PRINT HALLOW DIAMOND PATTERN USING WHILE LOOP
Views: 79 | Author: sunny_jain
// using while loop to make a hollow diamond pattern
#include <stdio.h>
int main()
{
    int n = 5, rows = 1, columns;
    while (rows <= n ) {
        columns = n;
        while(columns > rows) {
            printf(" ");
            columns--;
        }
        printf("*");
        columns = 1;
        while (columns < (rows-1)*2) {
            printf(" ");
            columns++;
        }
        if(rows == 1){
            printf("\n");
        }
        else {
            printf("*\n");
        }
        rows++;
    }
    rows = n-1;
    while(rows >= 1) {
        columns = n;
        while(columns > rows) {
            printf(" ");
            columns--;
        }
        printf("*");
        columns = 1;
        while(columns < (rows-1)*2) {
            printf(" ");
            columns++;
        }
        if(rows == 1) {
            printf("\n");
    }
    else {
        printf("*\n");
    }
    rows--;
}
return 0;
}

Comments