Description
编写程序,输入10个整数到一个数组中,然后显示类似于下面的表格,即给出每一个数据值和每个数值占所有10个数值总和的百分比。
Input
输入10个正整数
Output
输出每一个数值值及其占所有10个数值总和的百分数。(输出中的短横线有4条,百分比的输出保留2位小数)
Sample Input
8 12 18 25 24 30 28 22 23 10
Sample Output
n----percentage of total
8----4.00
12----6.00
18----9.00
25----12.50
24----12.00
30----15.00
28----14.00
22----11.00
23----11.50
10----5.00
求代码指导~~
#include <stdio.h>
int main()
{
int s=0,i,a[10];
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
s+=a[i];
}
printf("n----percentage of total\n");
for(i=0;i<10;i++)
printf("%d----%.2f\n",a[i],100.0*a[i]/s);
return 0;
}