Contact Learn C
Copy

Program 21: To print diamond for 3 rows

Program 21:
 
#include<stdio.h>
main()
{
 int i,j,k,count=2;
 for(i=1;i<=5;i+=2)
 {
  for(k=1;k<=count;k++)
  {
   printf(" ");
  }
  count--;
  for(j=1;j<=i;j++) 
  { 
   printf("*"); 
  }  
  printf("\n"); 
 } 
 count=1; 
 for(i=3;i>=1;i-=2)
 {
  for(k=1;k<=count;k++) 
  { 
   printf(" "); 
  } 
  count++; 
  for(j=i;j>=1;j--)
  {
    printf("*");
  }
  printf("\n");
 }
}
Explanation: This is same as the program

Output:

Print diamond for 3 rows
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide