gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
c语言将位置信息存储到数组中
- User
c语言将位置信息存储到数组中
- Assistant
可以使用结构体存储位置信息,并将结构体数组作为一个整体来存储多个位置信息。
例如:
#include <stdio.h> // 坐标结构体 typedef struct { float x; float y; } Coordinate; int main() { // 定义结构体数组 Coordinate positions[5]; // 存储位置信息 for (int i = 0; i < 5; i++) { printf("请输入第%d个位置的坐标(x y):", i+1); scanf("%f %f", &positions[i].x, &positions[i].y); } // 输出位置信息 printf("位置信息如下:\n"); for (int i = 0; i < 5; i++) { printf("第%d个位置:(%f, %f)\n", i+1, positions[i].x, positions[i].y); } return 0; }运行结果:
请输入第1个位置的坐标(x y):1.23 4.56 请输入第2个位置的坐标(x y):2.34 5.67 请输入第3个位置的坐标(x y):3.45 6.78 请输入第4个位置的坐标(x y):4.56 7.89 请输入第5个位置的坐标(x y):5.67 8.90 位置信息如下: 第1个位置:(1.230000, 4.560000) 第2个位置:(2.340000, 5.670000) 第3个位置:(3.450000, 6.780000) 第4个位置:(4.560000, 7.890000) 第5个位置:(5.670000, 8.900000)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.