#include "stdio.h"
float promote(int number, float price)
{
float sale = 1;
if (number > 100)
sale = 0.95;
else if (number >= 50)
sale = 0.97;
return price * sale;
}
int main(int argc, char *argv[])
{
printf("请依次输入 10 个商品的库存量、商品原价:\n");
int number[10] = {0};
float price[10] = {0};
for (int i = 0; i < 10; i++)
{
printf("请输入商品%d的库存量和原价,以空格分隔:", i + 1);
scanf("%d %f", number + i, price + i);
}
for (int i = 0; i < 10; i++)
{
printf("商品%d的库存、原价、优惠价分别是:%d\t%f\t%f\n", i + 1,
number[i], price[i], promote(number[i], price[i]));
}
return 0;
}
可私信,帮解决