This is a nested for loop program in which we are going to see how to print the above pattern of Diamond of palindrome numbers, with the help of the C Programming language.
#include <stdio.h>
int main()
{
int a = 1, num, space;
printf("Enter the number of Rows \n");
scanf("%d", &num);
space = num - 1;
while (space != 0)
{
printf(" ");
space--;
}
printf("%d \n", a);
space = num - 2;
for (int i = 1; i < num; i++)
{
a = 1;
for (int k = 1; k <= space; k++)
{
printf(" ");
}
for (int j = 0; j <= i * 2; j++)
{
if (j < i)
{
printf("%d", a);
a++;
}
else
{
printf("%d", a);
a--;
}
}
printf("\n");
space--;
}
for (int i = num - 1; i >= 1; i--)
{
space = num - i;
a = 1;
for (int k = 1; k <= space; k++)
{
printf(" ");
}
for (int j = 1; j <= i * 2 - 1; j++)
{
if (j < i)
{
printf("%d", a);
a++;
}
else
{
printf("%d", a);
a--;
}
}
printf("\n");
space--;
}
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP