小编Mar*_*TEP的帖子

在float中打印数组,其中size依赖于用户输入

我有一个家庭作业,要求用户输入一组实数.我必须将它们存储到大小为20的数组中,并且必须在floats中打印数组.

我的问题是我的阵列打印的数量超过了所需的五个数字.五个数字是10, 37, 15, 21, 18.

我需要帮助只打印五个数字,float一个小数位.

我在Oracle VM VirtualBox中使用Centos6.7,使用gedit文本编辑器.任何帮助表示赞赏.

#include <stdio.h>
#define SIZE 20


int main(void)
{
    int i, inputs[SIZE];

    printf("Enter real numbers, up to %d, q to quit\n", SIZE);
    for(i=0; i < SIZE; i++)
        scanf("%d", &inputs[i]);

    printf("You entered the following values:\n");
    for(i=0; i < SIZE; i++)
        printf("%4d", inputs[i]);
    printf("\n");

return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是该程序的输出:

[ee2372@localhost cprog]$ gcc jperez_aver.c
[ee2372@localhost cprog]$ ./a.out 
Enter real numbers, up to 20, q to quit
10 37 15 …
Run Code Online (Sandbox Code Playgroud)

c arrays floating-point printf

0
推荐指数
1
解决办法
141
查看次数

标签 统计

arrays ×1

c ×1

floating-point ×1

printf ×1