- 1

How can I write a code In C which produce a diamond pattern

Like this * *** ***** ****** ***** *** *

27th Apr 2022, 10:00 PM
Elly Karaseza
Elly Karaseza - avatar
3 Antworten
0
Look for a pattern Skip 3 spaces print 1 Skip 2 spaces print 3 Skip 1 space print 5 6 Skip 1 space print 5 Skip 2 spaces print 3 Skip 3 spaces print 1
27th Apr 2022, 11:33 PM
Raul Ramirez
Raul Ramirez - avatar
0
#include <stdio.h> int main(void) { int n; printf("Enter number of rows: \n"); scanf("%d",&n); int spaces=n-1; int stars=1; for(int i=1;i<=n;i++) { for(int j=1;j<=spaces;j++) { printf(" "); } for(int k=1;k<=stars;k++) { printf("*"); } if(spaces>i) { spaces=spaces-1; stars=stars+2; } if(spaces<i) { spaces=spaces+1; stars=stars-2; } printf("\n"); } return 0; }
4th May 2022, 11:19 PM
Nikoloz Tsereteli
Nikoloz Tsereteli - avatar
0
Here is my solution to print star diamond pattern. You need to print it in two steps. First upper triangle and then lower triangle. https://code.sololearn.com/ciNIECvqDGCt Here is the original solution of this pattern program https://www.techcrashcourse.com/2016/01/print-diamond-star-pattern-in-c.html . Hope it helps.
13th Jun 2022, 8:30 PM
Arun Kumar
Arun Kumar - avatar