C Language Nested Loops Set 22

Get the following output:

            1
         1 0
      1 0 1
   1 0 1 0
1 0 1 0 1

Source code : Using for loop

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

Source code : Using while loop

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

Get the following output:

            0
         0 1
      0 1 0
   0 1 0 1
0 1 0 1 0

Source code : Using for loop

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

Source code : Using while loop

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

Get the following output:

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1

Source code : Using for loop

code

Source code : Using while loop

code

Get the following output:

0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
1 0 1 0
0 1 0
1 0
0

Source code : Using for loop

code

Source code : Using while loop

code