Commit fc8b0469 by Gürcan Güleç

committing homework 2

parent 35eb18b6
Showing with 99 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// to limit random created numbers between certain values
int rndHigh = 100;
int rndLow = 1;
int clerk;
// filling the matrix with random values
void fillMatrix(int arr[100][100], int row, int column)
{
for (int i = 0; i<row; i++)
{
for (int j = 0; j<column; j++)
{
int rnd = rndLow + (rand() % (rndHigh - rndLow));
arr[i][j] = rnd;
}
}
}
// reading from the matrix
void readMatrix(int arr[100][100], int row, int column)
{
printf("\t ");
for(int c = 1; c<row+1; c++)
{
printf("C%d ", c);
}
printf("\n");
for (int i = 0; i<row; i++)
{
printf("ProDuck %d", i+1);
for (int j = 0; j<column; j++)
{
printf("%5d ", arr[i][j]);
}
printf("\n");
}
}
//finding the totals in each column
void findTotals(int arr[100][100], int row, int column)
{
printf(" Total");
for (int j = 0; j<column; j++)
{
int total = 0;
for (int i = 0; i<row; i++)
{
total = total + arr[i][j];
}
printf("%5d ", total);
}
printf("\n");
}
void findClerk(int arr[100][100], int row, int column)
{
int clerk;
int max = 0;
for (int j = 0; j<column; j++)
{
int total = 0;
for (int i = 0; i<row; i++)
{
total = total + arr[i][j];
}
if (max < total)
{
max = total;
clerk = j + 1;
}
}
printf("\n");
printf("Most ProDucktive Clerk: C%d", clerk);
printf("\n");
}
void displayMatrix(int arr[100][100], int row, int column)
{
readMatrix(arr,row,column);
findTotals(arr, row, column);
findClerk(arr, row, column);
}
int main()
{
srand ( time(NULL) );
int matrix[100][100];
int r = 5;
int c = 5;
fillMatrix(matrix,r,c);
displayMatrix(matrix, r, c);
return 0;
}
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