C Program to print diamond star pattern - DEEP CODER

Breaking

printf("Learn Deep Coding Here!!");

C Program to print diamond star pattern


C Program to print diamond star pattern

Write a C program to print diamond star pattern series using for loop. How to print diamond star pattern structure in C program. Logic to print diamond star pattern series in C programming.

#include <stdio.h> int main() { int i, j, rows; int stars, spaces; printf("Enter rows to print : "); scanf("%d", &rows); stars = 1; spaces = rows - 1; /* Iterate through rows */ for(i=1; i<rows*2; i++) { /* Print spaces */ for(j=1; j<=spaces; j++) printf(" "); /* Print stars */ for(j=1; j<stars*2; j++) printf("*"); /* Move to next line */ printf("\n"); if(i<rows) { spaces--; stars++; } else { spaces++; stars--; } } return 0; }


OUTPUT:


No comments:

Post a Comment