Silly doubt, how can i print numbers in sequence in C programming according to its variable value. my Code
愚蠢的怀疑,我如何根据其变量值在C编程中按顺序打印数字。我的代码
#include <stdio.h>
void main()
{
int i,j,result;
for (i=1;i<=4;i++)
{
for (j=i;j<=i;j++)
{
printf("%d\n%d",i,j+1);
}
}
}
getting output as
获得输出
1
22
33
44
Expecting answer is:
期待的答案是:
1
22
333
4444
3 个解决方案
#1
4
void main()
{
int i,j,result;
for (i=1;i<=4;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
#2
1
It could help you. Note that in C
array indexing starts at 0, not 1.
它可以帮助你。请注意,在C数组中,索引从0开始,而不是1。
void main()
{
int i,j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < i; ++j)
{
printf("%d", i);
}
printf("\n");
}
}
#3
0
#include <stdio.h>
void main()
{
int i,j,result;
for (i=1;i<=4;i++)
{
for (j=i;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
#1
4
void main()
{
int i,j,result;
for (i=1;i<=4;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}
#2
1
It could help you. Note that in C
array indexing starts at 0, not 1.
它可以帮助你。请注意,在C数组中,索引从0开始,而不是1。
void main()
{
int i,j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < i; ++j)
{
printf("%d", i);
}
printf("\n");
}
}
#3
0
#include <stdio.h>
void main()
{
int i,j,result;
for (i=1;i<=4;i++)
{
for (j=i;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}