你可以参考下我写的,销量价格什么的,我是随意赋值的。有好多类似的问题,比如统计成绩什么的,思路是一样的。
程序代码:
#include <stdio.h>
void output1(int m[][5],int n[][5],int s[]);
void output2(int m[][5],int n[][5],int s[]);
void output3(int m[][5],int n[][5],int s[]);
void output4(int m[][5],int n[][5],int s[]);
int main ()
{
int M[4][5],S[4][5],C[5];
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
M[i][j]=(i+1)*100+(j+1)*10;
S[i][j]=M[i][j]-(j+1);
}
}
for(i=0;i<5;i++)
{
C[i]=(i+1)*10+i;
}
printf("(1) Product and sales of different week and different product\n");
printf("(2) Total product and sales every week\n");
printf("(3) Total product and sales of different product in a month\n");
printf("(4) Total product and sales in a month\n");
printf("(5) Press 5 to EXIT\n");
int ce=1;
while(ce!=5)
{
scanf("%d",&ce);
switch(ce)
{
case 1: output1(M,S,C); break;
case 2: output2(M,S,C); break;
case 3: output3(M,S,C); break;
case 4: output4(M,S,C); break;
case 5: break;
default: break;
}
}
return 0;
}
void output1(int m[][5],int n[][5],int s[])
{
printf("Product of different week and different product:\n");
int i,j;
for(i=0;i<4;i++)
{
printf("Week(%d) ",i+1);
for(j=0;j<5;j++)
{
printf("%5d ",m[i][j]*s[j]);
}
printf("\n");
}
printf("Sales of different week and different product:\n");
for(i=0;i<4;i++)
{
printf("Week(%d) ",i+1);
for(j=0;j<5;j++)
{
printf("%5d ",n[i][j]*s[j]);
}
printf("\n");
}
}
void output2(int m[][5],int n[][5],int s[])
{
printf("Total product and sales every week:\n");
int i,j,sum;
for(i=0;i<4;i++)
{
printf("Week(%d) ",i+1);
sum=0;
for(j=0;j<5;j++)
{
sum+=m[i][j]*s[j];
}
printf("%d ",sum);
sum=0;
for(j=0;j<5;j++)
{
sum+=n[i][j]*s[j];
}
printf("%d\n",sum);
}
}
void output3(int m[][5],int n[][5],int s[])
{
int i,j,sum;
printf("Total product and sales of different product in a month:\n");
for(i=0;i<5;i++)
{
printf("Product(%d) ",i+1);
sum=0;
for(j=0;j<4;j++)
{
sum+=m[j][i]*s[i];
}
printf("%d ",sum);
sum=0;
for(j=0;j<4;j++)
{
sum+=n[j][i]*s[i];
}
printf("%d\n",sum);
}
}
void output4(int m[][5],int n[][5],int s[])
{
int i,j,sum1=0,sum2=0;
printf("Total product and sales in a month:\n");
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
sum1+=m[j][i]*s[i];
}
for(j=0;j<4;j++)
{
sum2+=n[j][i]*s[i];
}
}
printf("Total product = %d\n",sum1);
printf("Total sales = %d\n",sum2);
}
[此贴子已经被作者于2016-3-3 16:10编辑过]