HTMLify

PRINT HALLOW DIAMOND PATTERN BY FOR LOOP IN C
Views: 101 | Author: sunny_jain
// using for loop
#include <stdio.h>

int main()
{
    int n = 5, rows, columns;
    for (rows = 1; rows<= n; rows++) {
        for (columns = n ; columns>rows; columns--) {
            printf(" ");
        
        }
        printf("*");
        for (columns = 1; columns<(rows-1)*2; columns++) {
            printf(" ");
        }
        if ( rows==1){
            printf("\n");
        }
        else{
            printf("*\n");
        }
    }
    for (rows = n-1; rows>=1; rows--) {
        for (columns = n; columns > rows; columns--) {
            printf(" ");
        }
        printf("*");
        for (columns = 1; columns<(rows-1)*2; columns++){
            printf(" ");
        }
        if (rows == 1) {
            printf("\n");
        }
        else {
            printf("*\n");
        }
    }
    return 0;
}

Comments

abh 2024-03-23 08:47

Questions were not hard, just solutions were not easy
djdj 2024-03-27 08:28

@abh
😃⃢👍 verru good