This program always provide me a different output, I'm confused how is this possible. Error is in the last loop which is under if conditional statement but don't know what is it?
#include <stdio.h>
int main()
{
int n;
printf("Enter the number upto which the pattern is to be printed \n ");
scanf("%d", &n);
/* Upside inverted V */
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n - i; j++)
{
printf(" ");
}
for (int k = 1; k <= i; k++)
{
printf("%d", k);
}
if (i > 1)
{
for (int l = i - 1; l > 0; l--)
{
printf("%d", l);
}
}
printf("\n");
}
// down V part
for (int x = n - 1; x >= 1; x--)
{
for (int y = n; y > x; y--)
{
printf(" ");
}
for (int z = 1; z <= x; z++)
{
printf("%d", z);
}
if (x > 1)
{
for (int w = x - 1; w >= 1; w--)
{
printf("%d", &w);
}
}
printf("\n");
}
return 0;
}
Removing the last loop get me run one third of my program or the pattern which I had wanted.