Vous êtes sur la page 1sur 8

Vetores e Matrizes

Linguagem C
Vetores e Matrizes

Variável composta- Conjunto de variáveis identificadas por um mesmo nome ,


composta por valores diferentes.
Homogênea- Armazena elementos de um mesmo tipo.
Um vetor é uma matriz com apenas 1 dimensão.
– Quando a estrutura permite elementos de tipos diferentes, é
chamada de heterogênea.

Tipo:
char vetorChar[50];
Int vetorInt[50];
float vetorFloat[50];
double vetorDouble[50];
Qual a importância de um vetor?
Variáveis

#include <stdio.h>
int main(){ #include <stdio.h>
float nota1; int main(){
float nota2; float nota[3];
float nota3; nota[0] = 5.0;
nota1 = 5.0; nota[1] = 7.0;
nota2 = 7.0; nota[2] = 8.0;
nota3 = 8.0; return 0;
return 0; }
} Nota1 Nota2 Nota3 Nota[0] Nota[1] Nota[2]
5.0 7.0 8.0 5.0 7.0 8.0
Vetores

Uma vez que as variáveis que compõem o vetor têm o mesmo nome, o que
distingue cada um delas é um índice, [Index] que referencia sua localização
dentro da estrutura.
#include <stdio.h>
int main(){
float Vetor[3];
int i;
for(i=0; i < 3; i++){
printf("Entre com uma Nota: ");
scanf(“%f”,& Vetor[i]);
}
return 0;
}
Vetores

1#include <stdio.h> (i=0) 0 1 2


2 int main(){ Vetor 5.0 7.0 8.0
3 float Vetor[3];
4 int i;
5 for(i=0; i < 3; i++){ (i=1) 0 1 2
6 printf("Entre com uma Nota: "); Vetor 5.0 7.0 8.0
7 scanf(“%f”&Vetor[i]);
8}
9 return 0; (i=2) 0 1 2
10 }
7/85
Vetor 5.0 7.0 8.0
Matrizes

n-dimensional;

Tipo:
char vetorChar[50][90];
int vetorInt[50][90];
float vetorFloat[50][90];
double vetorDouble[50][90];
Matrizes

#include <stdio.h>
int main(){
float boletim[2][3];
int i, j;
for(i=0; i < 2; i++){
for(j=0; j < 3; j++){
if(i==0){
printf("Matemática:");
}else{
printf("Português: ");
}
scanf("%f", &boletim[i][j]);
}
}
return 0;
}
Questões

Ler um vetor de 10 números inteiros e imprimir na tela.

Vous aimerez peut-être aussi