"question_id":1072218,"question_title":"商家商品销售量统计","question_content":"<p>现在有一个网站上半年的商品销售量,请你写一段代码帮助店主统计前半年的总销量和平均销量。\n商品销售表\n1月份\t2月份\t3月份\t4月份\t5月份\t6月份\t总销量\t平均销量\n64\t53\t77\t59\t61\t42\t0\t0\n(1)函数中应定义一个包含8个元素的一维数据,用来存放6个月的商品销量和统计后的总销量及平均销量;\n(2)完成6个月销量的输入;\n(3)计算半年的总销量及平均销量;\n(4)按照程序运行效果图,输出商品销量表。\n![图片说明](https://img-ask.csdn.net/upload/202005/16/1589596638_852927.jpg)</p>","difficulty":"简单","answer_id":1274957,"answer_content":"表格上可能有点不同,你可以再改改\n```\n#include<stdio.h>\nint main()\n{\n\tint a[8],s=0;\n\tprintf(\"----------商家商品销售统计----------\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"请输入商品6个月的销售量:\");\n\tfor (int i = 0; i < 6; i++)\n\t{\n\t\tscanf(\"%d\", &a[i]);\n\t\ts += a[i];\n\t}\n\tprintf(\"\\n\\t\\t\\t商品销量表\\t\\t\\t\\n\");\n\tprintf(\"——————————————————————————————————————————————\\n\");\n\tfor (int i = 1; i <= 8; i++)\n\t{\n\t\tif (i <= 6)\n\t\t\tprintf(\" %d月份 \", i);\n\t\telse if (i == 7)\n\t\t\tprintf(\" 总销售 \");\n\t\telse\n\t\t\tprintf(\" 平均销售 \\n\");\n\t}\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tif (i < 6)\n\t\t\tprintf(\" %d |\", a[i]);\n\t\telse if (i == 6)\n\t\t{\n\t\t\ta[i] = s;\n\t\t\tprintf(\" %d |\", a[i]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta[i] = s / 6;\n\t\t\tprintf(\" %d |\",a[i]);\n\t\t}\n\t}\n\treturn 0;\n}\n```\n![图片说明](https://img-ask.csdn.net/upload/202005/17/1589691710_74517.png)\n","tag_name":"c语言","cpp":"#include<stdio.h>\nint main()\n{\n\tint a[8],s=0;\n\tprintf(\"----------商家商品销售统计----------\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"请输入商品6个月的销售量:\");\n\tfor (int i = 0; i < 6; i++)\n\t{\n\t\tscanf(\"%d\", &a[i]);\n\t\ts += a[i];\n\t}\n\tprintf(\"\\n\\t\\t\\t商品销量表\\t\\t\\t\\n\");\n\tprintf(\"——————————————————————————————————————————————\\n\");\n\tfor (int i = 1; i <= 8; i++)\n\t{\n\t\tif (i <= 6)\n\t\t\tprintf(\"\t%d月份 \", i);\n\t\telse if (i == 7)\n\t\t\tprintf(\"\t总销售 \");\n\t\telse\n\t\t\tprintf(\"\t平均销售 \\n\");\n\t}\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tif (i < 6)\n\t\t\tprintf(\"\t %d |\", a[i]);\n\t\telse if (i == 6)\n\t\t{\n\t\t\ta[i] = s;\n\t\t\tprintf(\"\t %d |\", a[i]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta[i] = s / 6;\n\t\t\tprintf(\"\t %d |\",a[i]);\n\t\t}\n\t}\n\treturn 0;\n}","topic_link":"https://bbs.csdn.net/topics/600470258","status":1,"keywords":"动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术","license":"csdn.net","notebook":{"cpp":"https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/44.ipynb?type=file"},"notebook_enable":1,"author":"qq_32654125"