简体   繁体   English

我如何在单行上打印数字

[英]How can i print numbers on single line

Silly doubt, how can i print numbers in sequence in C programming according to its variable value. 愚蠢的疑问,我如何才能按照C变量的可变值顺序打印数字。 my Code 我的密码

#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
void main()
{  
   int i,j,result;
   for (i=1;i<=4;i++)
   {
     for (j=1;j<=i;j++)
     {
       printf("%d",i);
     }
     printf("\n");
   }
}

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");
    }
}
#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");
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 printf 中打印最多 x 个十进制数字? - How can i print up to x decimal numbers in printf? 如何打印内部为零的数字? - How can I print numbers that has zero inside? 如何在单个记忆字中编码一组数字? - How can I encode a sets of numbers in a single memory word? 如何在 c 的一行中打印不同的 arrays? - How to print different arrays in a single line in c? 如何从stdin中读取一行数字并计算其平均值? - How can i read a line of numbers from stdin & compute their average? 如何在 C 程序中打印序数指标? 无法打印带有 'st'、'nd'、'rd' 的数字。 (初学者) - How do I print ordinal indicators in a C program? Can't print numbers with 'st', 'nd', 'rd'. (Beginner) 如何使下一个printf()在同一行而不是在其下打印? - How can I make the next printf() to print on the same line and not below it? c-如何在一行中打印指定数量的字符 - c - how can I print specified count of a char in a line 如何使函数通过命令行打印出一定数量的随机数? C - How do I make a function print out a certain amount of Random numbers through the command line? C 如何将一行中未知数量的数字作为输入并将每个数字分配给一个变量? - How do I take an unknown amount of numbers in a single line as input and assign each number to a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM