gpt4 book ai didi

c - 如何将报表打印到不同的列中

转载 作者:行者123 更新时间:2023-11-30 15:43:46 24 4
gpt4 key购买 nike

目前,我的简单数组程序正在生成我想要的数据,但我希望它采用更清晰的格式,如下所示:

Element[0] = 100      Element[26] = 126
Less than 125 Greater than 125
Element[1] = 101 Element[27] = 127
Less than 125 Greater than 127

等等

#include <stdio.h>

int main ()
{
int arr[ 51 ]; /* arr is an array of 10 integers */
int x,y;

/* initialize elements of arr[] to 0 */
for ( x = 0; x < 51; x++ )
{
arr[ x ] = x + 100; /* set element at int x to x + 100 */
}

/* outputs the value of each arra y element */
for (y = 0; y < 51; y++ )
{
if (y <= 25)
{
printf("Element[%d] = %d\n", y, arr[y]) && printf(" This is less than 125\n");
}
if (y >=26)
{
printf("Element[%d] = %d\n", y, arr[y]) && printf(" This is greater than 125\n");
}
}


return 0;
}

任何帮助将不胜感激!

最佳答案

如果我猜对了,您希望在值后面的同一行上打印“This is ... than 125”?然后只需打印值但不带换行符,后跟文本(带换行符)。

喜欢

printf("Element[%02d] = %-3d", y, arr[y]);

if (arr[y] < 125)
printf("\tThis is less than 125\n");
else if (arr[y] == 125)
printf("\tThis is equal to 125\n");
else
printf("\tThis is greater than 125\n");

关于c - 如何将报表打印到不同的列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com