C program to print a diamond shape - 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....

Wednesday, December 18, 2019

C program to print a diamond shape - My CS Tutorial

C program to create a diamond shape by using alphabets.
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 alphabets.
In the first we will enter the range of rows or alphabets then the shape will be print on to the output screen.



C program code



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


OUTPUT:





This is a solid diamond shape. we can see that shape is create by using alphabets.In this output the number of rows is 18 and the alphabets printed in this shape are 18(as R is available on 18th number in alphabets range or group).



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