Discussion Forums

New User? Please read instructions!

C program to print diamond pattern  

  RSS

thiyagarajan.s
Active Member
Joined: 5 months  ago
Posts: 14
27/01/2017 10:03 am  

C program to print diamond pattern


ReplyQuote
prakash
Eminent Member
Joined: 5 months  ago
Posts: 20
16/02/2017 1:31 pm  

Hi,

C program to print diamond pattern is below.

 

#include <stdio.h>

int main()

{

     int i, j, rows, space = 1;

 

     printf("Please enter number of rows you want to see in half Diamond\n");

     scanf("%d", &rows);

 

     printf("Diamond pattern:\n");

 

     space = rows - 1;

 

     for (j = 1; j <= rows; j++)

     {

          for (i = 1; i <= space; i++)

          printf(" ");

 

          space--;

 

          for (i = 1; i <= 2*j-1; i++)

          printf("*");

          printf("\n");

     }

 

     space = 1;

 

     for (j = 1; j <= rows - 1; j++)

     {

          for (i = 1; i <= space; i++)

          printf(" ");

 

          space++;

 

          for (i = 1 ; i <= 2*(rows-j)-1; i++)

          printf("*");

 

          printf("\n");

     }

     return 0;

}

 

Output:

Please enter number of rows you want to see in half Diamond

5

Diamond pattern:

    *

   ***

  *****

 *******

*********

 *******

  *****

   ***

    *

 


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!