C Program to print Simple Diamond Pattern using Star(*) for n number of lines.[Pattern 20]| Using C language| C Program series 41|
Code :
For n number of LINES:
/*
C Program to print Simple Diamond Pattern using Star(*) for n number of lines.[Pattern 20]
For Example:n=9
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
*/
#include<stdio.h>
main()
{
printf("C Program to print Simple Diamond Pattern using Star(*) for n number of lines.[Pattern 20]\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 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++)
{
printf("* ",i);
}
}
else
{
for(j=1;j<=i-half-1;j++)
{
printf(" ");
}
for(k=n-i+1;k>0;k--)
{
printf("* ");
}
}
printf("\n\t");//here, '\t' used to shift pattern 1 tab space right side
}
}
The output of Code:
![C Program to print Simple Diamond Pattern using Star(*) for n number of lines.[Pattern 20]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQHGgfHnnPXrrTsDj5_TkFnepS_4G03RaUxZMWH-hCY53igEzwbviZmhga_Bz0wbq6lH4vchtNIryzGkNBhmt17Y84a6qHdCyKDnjVYXc-dT6tQmOVGMRaCVS83bweGw57NDDQcaV-Eu8d1VZoyuXkBTyS1uNFsV3d-D0Q3gSvSZnmGhHMXqKhDiU/w640-h194/Screenshot%202022-11-12%20152623.jpg)
![C Program to print Simple Diamond Pattern using Star(*) for n number of lines.[Pattern 20]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6zVpx5l1e3LFThk8dLbOxDS4wOWGeezZy0aAslYFR5f4HKVUJ7l51m7XO08c5zWFzOwdcIjpKMijaT6sNwUwzxNvtf-l02gXYo5VZNNkYEZ-dz5n4cPi12xcCInr-DKAzI6_pI7YfDCcVPrfpO-C-Ktu4mjUaSsFpDEzwd0zDn63ISxXJMdQjrzs/w640-h322/Screenshot%202022-11-12%20152642.jpg)
Comments
Post a Comment