C program to create or print a diamond or solid diamond symbol pattern - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Tuesday, December 24, 2019

C program to create or print a diamond or solid diamond symbol pattern - My CS Tutorial

C program to create a diamond shape by using symbols.
In this tutorial we will learn how to write a c programming code to create or print a diamond or solid diamond shape by using symbols.
In the first we will enter the range of rows or symbols' lines then the shape will be print on to the output screen.



C program source code


#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b,c,count,num;
 printf("\n Enter number of rows:\n ");
 scanf("%d",&num);
 count=num-1;
 for(a=1;a<=2*(num)-1;a+=2)
 {
  for(c=1;c<=count;c++)
  {
   printf(" ");
  }
  count--;
  for(b=1;b<=a;b++)
  {
   printf("*");
  }
  printf("\n");
 }  
 count=1;
 for(a=2*(num)-1;a>=1;a-=2)
 {
   if(a!=(2*(num)-1))
   {
     for(c=1;c<=count;c++)
     {
      printf(" ");
     }
     count++;
     for(b=a;b>=1;b--)
     {
       printf("*");
     }
     printf("\n");
   }
 }
 getch();
}


OUTPUT:





We can see that it is a diamond pattern by symbols.
In the first we will enter the range of rows then print the solid diamond symbol pattern.
In this output the range of rows are 15.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment