c program to print diamond pattern, C Program to Print Diamond in C , Diamond Shape in C Language, C Assignment to print Diamond shape in C
#include
int main()
{
int n, c, k, space = 1;
printf("Enter number of rows\n");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2*k-1; c++)
printf("*");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1 ; c <= 2*(n-k)-1; c++)
printf("*");
printf("\n");
}
return 0;
}
OUTPUT :
*
***
*****
***
*
Please provide a c program for below pattern:
ReplyDelete12345
12 45
1 5
12 45
12345
#include
Deletemain()
{
int i,j,k=1;
for(i=1;i<=5;i++)
{
k=1;
for(j=1;j<=5;j++)
{
if((i==2 && j==3) || (i==4 && j==3))
{ printf(" "); }
else if(i==3 && j==2)
{
j=k=4;
printf(" ");
}
else
{ printf("%d",k); }
k++;
}
printf("\n");
}
In the comment published, in middle row 5 should come extreme end...sorry for mistake
ReplyDeleteThis comment has been removed by the author.
ReplyDelete