-
Notifications
You must be signed in to change notification settings - Fork 0
/
matriz.c
51 lines (44 loc) · 956 Bytes
/
matriz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int m[4][4];
int somadalinha3 = 0;
float somadacoluna2 = 0;
float somadamatriz = 0;
float mGeo = 1;
float mediaGeo;
//Setting a different seed
srand(time(NULL));
for (int j = 0; j <= 3; j++)
{
for (int i = 0; i <= 3; i++)
{
m[i][j] = (rand() % 11 + 5);
somadamatriz += m[i][j];
if (j == 2)
somadalinha3 += m[i][j];
if (i == 1)
somadacoluna2 += m[i][j];
if (i == j)
mGeo = mGeo *m[i][j];
}
}
for (int j = 0; j <= 3; j++)
{
printf("\n");
for (int i = 0; i <= 3; i++)
{
printf(" %d |", m[i][j]);
}
}
mediaGeo = pow(mGeo, (1 / 4));
printf("\n\nSoma da matriz: %.0f\n", somadamatriz);
printf("Media da matriz: %.2f\n", somadamatriz / 16);
printf("Soma da 3a linha: %d\n", somadalinha3);
printf("Media da 2a coluna: %.2f\n", somadacoluna2 / 4);
printf("Media geometrica: %.2f\n", mediaGeo);
return 0;
}