C Program to print Diamond outline Pattern using Star(*) for n number of lines.[Pattern 21]| Using C language| C Program series 42|
Code :
For n number of LINES:
/*
C Program to print Diamond outline Pattern using Star(*) for n number of lines.[Pattern 21]
For Example:n=9
*
* *
* *
* *
* *
* *
* *
* *
*
*/
#include<stdio.h>
main()
{
printf("C Program to print Diamond outline Pattern using Star(*) for n number of lines.[Pattern 21]\n\n");
int i,j,k,n;
printf("Enter the ODD number of lines:");
scanf("%d",&n);
if(n%2==0)
{
n=n+1;
}
printf("Number Diamond outline Pattern for %d lines.\n\n\t",n);
int half=n/2;
for(i=1;i<=n;i++)
{
if(i<=half+1)
{
for(j=half+1-i;j>0;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(j==1 || j==i)
printf("* ",i);
else
printf(" ",i);
}
}
else
{
for(j=1;j<=i-half-1;j++)
{
printf(" ");
}
for(k=n-i+1;k>0;k--)
{
if(k==1 || k==n-i+1)
printf("* ",i);
else
printf(" ",i);
}
}
printf("\n\t");//here, '\t' used to shift pattern 1 tab space right side
}
}
The output of Code:

![C Program to print Diamond outline Pattern using Star(*) for n number of lines.[Pattern 21]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCZLFBvc9ei0XrzuIJix_sBSsvrHBy693XHRFlsmIyvpZFTrPELpyiTRo_ccLijcLJOVRnijFooBNQ2u2XLUzVJhlBxC0bsCv0WYQr6EoEHdPYP-gjCqYZd0LI90WCvFQ54ZVySTCDgMbL7unvwlYcp1ZAlG3-PNqgtTqpLNgxX9st6C9CIgB5CnQ/w640-h204/Screenshot%202022-11-13%20163257.jpg)
![C Program to print Diamond outline Pattern using Star(*) for n number of lines.[Pattern 21]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicntTQoK8NqSzmhoHEsf-25l4cppuJ6DC3Q54hfD_r5GxJrHYv0ksJYfAIWlCP1BlB-H0eEjF52A7QNRgCIO0blPvjMfuEWT7C0ztmoZTc3cxQt0F9PU_QEUUjT2KBmCijO2TLEmZ6-C9-g8xBh9UtFWVm0cQBbqabSIIWqhPkttygEgy5HnPQhqg/w640-h318/Screenshot%202022-11-13%20163334.jpg)
Comments
Post a Comment