-
Notifications
You must be signed in to change notification settings - Fork 0
/
82.c
45 lines (37 loc) · 1012 Bytes
/
82.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
#include <stdio.h>
int main()
{
/*
Ler dois conjuntos de números reais, armazená-los em vetores e calcular o
produto escalar entre eles. Os conjuntos têm 5 elementos cada. Imprimir os
dois conjuntos e o produto escalar, sendo que o produto escalar é dado por: x1
* y1 + x2 * y2 + ... + xn * yn.
*/
float C1[5], C2[5], Mult[5], escalar = 0;
int i;
//Montagem dos dois conjuntos
for(i = 0; i < 5; i++) {
printf("Digite a posicao %d do conjunto 1: ", i);
scanf("%f", &C1[i]);
printf("Digite a posicao %d do conjunto 2: ", i);
scanf("%f", &C2[i]);
//Vetor do produto escalar
Mult[i] = C2[i] * C2[i];
}
//Montar o produto escalar
for(i = 0; i < 5; i++) {
escalar = escalar + Mult[i];
}
//Mostar conjunto 1
printf("\n O CONJUNTO 1: ");
for(i = 0; i < 5; i++) {
printf("%f \n", C1[i]);
}
//Mostar Conjunto 2
printf("\n O CONJUNTO 2: ");
for(i = 0; i < 5; i++) {
printf("%f \n", C2[i]);
}
printf("\n O Produto escalar eh igual a: %f", escalar);
return 0;
}