1
1*2
1*2*3
1*2*3*4
i used as outer loop variable for printing no. of lines=4
j used to control printing * and nos. in each line.
In this pattern, we can figure out that star does not get printed when value of i equals value of j.
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
if(i!=j)
printf("*");
}
printf("\n");
}
return 0;
}
1*2
1*2*3
1*2*3*4
i used as outer loop variable for printing no. of lines=4
j used to control printing * and nos. in each line.
In this pattern, we can figure out that star does not get printed when value of i equals value of j.
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
if(i!=j)
printf("*");
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment