C Language Nested Loops Set 17

Get the following output:

            1
         1 3
      1 3 5
   1 3 5 7
1 3 5 7 9
   1 3 5 7
     1 3 5
       1 3
          1

Source code: Using for loop

#include<stdio.h>
int main()
{
	int i,j,k,n=5;
	for(i=1;i<=5;i++)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=1;j<=i;j++)
		{
			printf("%d ",j*2-1);
		}
		printf("\n");
		n--;
	}
	n=2;
	for(i=4;i>=1;i--)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=1;j<=i;j++)
		{
			printf("%d ",j*2-1);
		}
		printf("\n");
		n++;
	}
	return(0);
}

Source code: Using while loop

#include<stdio.h>
int main()
{
	int i=1,j,k,n=5;
	while(i<=5)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=1;
		while(j<=i)
		{
			printf("%d ",j*2-1);
			j++;
		}
		printf("\n");
		i++;
		n--;
	}
	i=4;
	n=2;
	while(i>=1)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=1;
		while(j<=i)
		{
			printf("%d ",j*2-1);
			j++;
		}
		printf("\n");
		i--;
		n++;
	}
	return(0);
}

Get the following output:

            1
         2 1
      3 2 1
   4 3 2 1
5 4 3 2 1
   4 3 2 1
      3 2 1
         2 1
            1

Source code: Using for loop

#include<stdio.h>
int main()
{
	int i,j,k,n=5;
	for(i=1;i<=5;i++)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=i;j>=1;j--)
		{
			printf("%d ",j);
		}
		printf("\n");
		n--;
	}
	n=2;
	for(i=4;i>=1;i--)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=i;j>=1;j--)
		{
			printf("%d ",j);
		}
		printf("\n");
		n++;
	}
	return(0);
}

Source code: Using while loop

#include<stdio.h>
int main()
{
	int i=1,j,k,n=5;
	while(i<=5)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=i;
		while(j>=1)
		{
			printf("%d ",j);
			j--;
		}
		printf("\n");
		i++;
		n--;
	}
	i=4;
	n=2;
	while(i>=1)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=i;
		while(j>=1)
		{
			printf("%d ",j);
			j--;
		}
		printf("\n");
		i--;
		n++;
	}
	return(0);
}

Get the following output:

            1
         3 1
      5 3 1
   7 5 3 1
9 7 5 3 1
   7 5 3 1
      5 3 1
        3 1
           1

Source code: Using for loop

#include<stdio.h>
int main()
{
	int i,j,k,n=5;
	for(i=1;i<=5;i++)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=i;j>=1;j--)
		{
			printf("%d ",j*2-1);
		}
		printf("\n");
		n--;
	}
	n=2;
	for(i=4;i>=1;i--)
	{
		for(k=1;k<=n;k++)
		printf("  ");
		for(j=i;j>=1;j--)
		{
			printf("%d ",j*2-1);
		}
		printf("\n");
		n++;
	}
	return(0);
}

Source code: Using while loop

#include<stdio.h>
int main()
{
	int i=1,j,k,n=5;
	while(i<=5)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=i;
		while(j>=1)
		{
			printf("%d ",j*2-1);
			j--;
		}
		printf("\n");
		i++;
		n--;
	}
	i=4;
	n=2;
	while(i>=1)
	{
		k=1;
		while(k<=n)
		{
			printf("  ");
			k++;
		}
		j=i;
		while(j>=1)
		{
			printf("%d ",j*2-1);
			j--;
		}
		printf("\n");
		i--;
		n++;
	}
	return(0);
}