任务条件:使用结构类型和预处理器指令,编写N类计算机设备输入信息的程序,即制造商、类型(打印机、扫描仪、膝上型计算机、鼠标、键盘)、颜色、型号,按公式y= 3x ^2+ 4x-2计算价格,其中x是选项数加上N。
#define N 5
#define M 15
#define PRI(X) 3*X*X+4*X-2
typedef struct Ctechnology
{
char firma[M];
char type[M];
int price[N];
} comp;
int main()
{
comp a;
printf("Firm, type, price - (y=3x^2+4x-2)\n ");
for (int i = 0; i < N; i++)
{
a.price[N] = PRI(((i + 1)+N)); // there is a problem
printf("%d) ", i + 1);
scanf("%s %s", a.firma, a.type);
printf("\n | [%d] | Firm %10s | Type %10s | Price %10d |\n", i + 1, a.firma, a.type, a.price[N]);
}
return 0;
}发布于 2022-03-24 10:51:33
正在运行
#define N 5
#define M 15
#define PRI(X) 3*X*X+4*X-2
price[N] = PRI(((i + 1)+N));通过gcc -E (运行预处理程序),我们可以
price[5] = 3*((i + 1)+5)*((i + 1)+5)+4*((i + 1)+5)-2;通常,您可能希望在指令中在Xes周围添加括号,因此不管输入如何,它们都是正确分组的:
#define PRI(X) 3*(X)*(X)+4*(X)-2 ->
price[5] = 3*(((i + 1)+5))*(((i + 1)+5))+4*(((i + 1)+5))-2;然后,当然,有一个问题,price[N]始终是一个禁区的访问.
https://stackoverflow.com/questions/71601048
复制相似问题