|
-
March 8th, 2012, 02:25 PM
#1
please help me with this code..
hello please help me..i try run this code to do double dimensional array and looping..i don't have error but the output cant view:
#include <stdio.h>
#define num_staff 5
#define week 4
int minimum(const int sales[] [week], int staff, int sales_shoes);
int maximum(const int sales[] [week], int staff, int sales_shoes);
double average(const int setofSales[], int sales_shoes);
void printArray(const int sales[][week], int staff, int sales_shoes);
int loop ( const int sales[][week], int staff, int sales_shoes);
int main(void)
{
int nums_staff;
const int totalSales[num_staff][week]= {{ 15 , 18 , 16 , 13 },
{26 , 17 , 19 , 18 },
{21 , 7 , 13 , 10 },
{24 , 27 , 15 , 19 },
{ 10 , 20 , 16 , 11 }};
/* output array statement*/
printf("THE ARRAY IS:\n");
printArray(totalSales, num_staff, week);
/*determine min and max sales value*/
printf("\n\n min_Sales: %d\n max_Sales:%d\n", minimum(totalSales,num_staff,week),
maximum(totalSales,num_staff,week));
for(nums_staff = 0; nums_staff < num_staff; nums_staff++){
printf("the average sales for number staff %d is %.2f\n", nums_staff, average(totalSales[nums_staff],week));
}
return 0;
}
int minimum(const int sales[][week],int staff, int sales_shoes)
{
int i;
int j;
int lowSales = 100;
for (i= 0; i < staff; i++){
for (j= 0; j < week; j++){
if(sales[i][j] < lowSales){
lowSales = sales[i][j];
}
}
}
return lowSales;
}
int maximum(const int sales [][week],int staff, int sales_shoes)
{
int i;
int j;
int highSales = 0;
for(i = 0; i < staff; i++){
for (j = 0; j < week; j++){
if(sales[i][j] >highSales){
highSales = sales[i][j];
}
}
}
return highSales;
}
double average(const int setofsales[], int sales_shoes)
{
int i;
int total = 0;
for (i =0; i<sales_shoes; i++){
total +=setofsales[i];
}
return(double)total/sales_shoes;
}
void printArray(const int sales[][week], int staff, int sales_shoes)
{
int i;
int j;
printf(" [1] [2] [3] [4]");
for(i= 0; i < staff; i++){
printf("\n totalSales[%d]", i);
for (j= 0; j < sales_shoes; j++){
printf("%-Sd", sales[i][j]);
}
}
}
int loop ( const int sales[][week], int staff, int sales_shoes)
{
int i;
int j;
int lowSales;
for (i = 0; i < staff; i++){
for ( j= 0; j < sales_shoes; j++){
if ( sales[i][j] < lowSales){
lowSales = sales [i][j];
}
}
}
return lowSales;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|