Commit 90085fc6 by muhega

Upload New File

parent 586aff2c
Showing with 145 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
int scan1();
int scan2();
void scan3(int row, int col,int array[row][col]);
void printing1(int row,int col,int array[row][col]);
void sum(int row,int col,int array[row][col],int total[col]);
void most(int size,int total[size]);
int main()
{
int rows=scan1(),cols=scan2();
int arr[rows][cols],tot[cols];
scan3(rows,cols,arr);
printf("sales matrix\n");
printing1(rows,cols,arr);
sum(rows,cols,arr,tot);
most(cols,tot);
return 0;
}
int scan1()
{
int row,br=5;
printf("please enter the number of product groups, PS: maximum 15\n");
while (br>0)
{
scanf("%d",&row);
if (row<=15 && row>0)
{
break;
}
else
{
printf("invalid number please enter again\n");
}
}
return row;
}
int scan2()
{
int col,br=5;
printf("please enter the number of salesclerks, PS: maximum 15\n");
while (br>0)
{
scanf("%d",&col);
if (col<=15 && col>0)
{
break;
}
else
{
printf("invalid number please enter again\n");
}
}
return col;
}
void scan3(int row, int col,int array[row][col])
{
int i,j;
for(j=0;j<col;j++)
{
for(i=0;i<row;i++)
{
printf("enter number of products sold by clerk %d for product group %d \n",(j+1),(i+1));
scanf("%d",&array[i][j]);
}
}
return;
}
void printing1(int row,int col,int array[row][col])
{
int nrow=row+1,ncol=col+1,i,j;
for(i=0;i<nrow;i++)
{
if (i==0)
{
for(j=0;j<ncol;j++)
{
if(j==0)
{
printf("\t\t");
}
else
{
printf("C%02d\t",j);
}
}
}
else
{
for(j=0;j<ncol;j++)
{
if(j==0)
{
printf("PRODUCT%02d\t",i);
}
else
{
printf("%3d\t",array[(i-1)][(j-1)]);
}
}
}
printf("\n");
}
return;
}
void sum(int row,int col,int array[row][col],int total[col])
{
int i,j,ncol=col+1;
for(j=0;j<col;j++)
{
total[j]=0;
for(i=0;i<row;i++)
{
total[j]+=array[i][j];
}
}
for(j=0;j<ncol;j++)
{
if (j==0)
{
printf(" total\t");
}
else
{
printf("%3d\t",total[(j-1)]);
}
}
return;
}
void most(int size,int total[size])
{
int i,big=total[0],index=0;
for(i=0;i<size;i++)
{
if (total[i]>big)
{
big=total[i];
index=i+1;
}
}
printf("\nmost productive clerk: C%02d",index);
return;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment