Get the following output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Source code: Using for loop
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
return(0);
}
Source code: Using while loop
#include<stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=i)
{
printf("%d ",j);
j++;
}
printf("\n");
i++;
}
i=5;
while(i>=1)
{
j=1;
while(j<=i)
{
printf("%d ",j);
j++;
}
printf("\n");
i--;
}
return(0);
}
Get the following output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Source code: Using for loop
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
return(0);
}
Source code: Using while loop
#include<stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=i)
{
printf("%d ",j);
j++;
}
printf("\n");
i++;
}
i=4;
while(i>=1)
{
j=1;
while(j<=i)
{
printf("%d ",j);
j++;
}
printf("\n");
i--;
}
return(0);
}
Get the following output:
2
2 4
2 4 6
2 4 6 8
2 4 6 8 10
2 4 6 8
2 4 6
2 4
2
Source code: Using for loop
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j*2);
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d ",j*2);
}
printf("\n");
}
return(0);
}
Source code: Using while loop
#include<stdio.h>
int main()
{
int i=1,j;
while(i<=5)
{
j=1;
while(j<=i)
{
printf("%d ",j*2);
j++;
}
printf("\n");
i++;
}
i=4;
while(i>=1)
{
j=1;
while(j<=i)
{
printf("%d ",j*2);
j++;
}
printf("\n");
i--;
}
return(0);
}




