A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Computação Eletrônica

Apresentações semelhantes


Apresentação em tema: "Computação Eletrônica"— Transcrição da apresentação:

1 Computação Eletrônica
Vetores e Matrizes

2 Vetor Conjunto de variáveis de um mesmo tipo que são acessadas através de índices Tipo estruturado homogêneo Declaração var identificador:array[vi .. vf] of tipo; onde vi <= vf

3 Vetores program somaVetor; var i, soma: integer;
numeros: array[1..5] of integer; begin numeros[1] := 3; numeros[2] := 7; numeros[3] := 2; numeros[4] := 4; numeros[5] := 5; i := 1; soma := 0; while (i <= 5) do soma := soma + numeros[i]; i := i + 1; end; writeln('soma = ', soma); end.

4 Vetores program vetor; var vetorDeNumeros: array[1..5] of integer;
i: integer; begin i := 1; while i <= 5 do write('Entre um numero: '); readln(vetorDeNumeros[i]); i := i + 1; end; i := 5; while i >= 1 do writeln('Numero: ',vetorDeNumeros[i]); i := i - 1; readln; end. 

5 Vetores program data; var meses: array[1..12] of String;
dia, mes, ano: integer; begin meses[1] := 'Janeiro'; meses[2] := 'Fevereiro'; meses[3] := 'Marco'; meses[4] := 'Abril'; meses[5] := 'Maio'; meses[6] := 'Junho'; meses[7] := 'Julho'; meses[8] := 'Agosto'; meses[9] := 'Setembro'; meses[10] := 'Outubro'; meses[11] := 'Novembro'; meses[12] := 'Dezembro'; write('Entre a data: '); readln(dia,mes,ano); write(dia,' de ',meses[mes], ' de ', ano); readln; end.

6 Vetores Program contaAcimaDaMedia; var notas: array[1..5] of real;
acimaDaMedia: integer; i: integer; soma, media: real; begin i := 1; acimaDaMedia := 0; while (i <= 5) do write('Entre a nota: '); readln(notas[i]); soma := soma + notas[i]; i := i + 1; end; media := soma / 5; if (notas[i] > media) then acimaDaMedia := acimaDaMedia + 1; writeln('Media :', media:5:2); write('Acima da media: ',acimaDaMedia); readln; end.

7 For x While program forWhile1; program forWhile2;
var uns: array[1..5] of integer; i: integer; begin for i := 1 to 5 do uns[i] := 1; end; end. program forWhile2; var uns: array[1..5] of integer; i: integer; begin i := 1; while (i <= 5) do uns[i] := 1; i := i + 1; end; end.

8 While e for: correção de prova
{ Programa que: 1) lê o gabarito de 10 questões (respostas em número real) 2) lê o número de matrícula e as respostas dos alunos 3) imprime a nota Quando o número de matrícula for 9999 o programa termina. } Program correcao; var gabarito, resposta: array[1..10] of real; nota, matricula, i: integer; begin for i := 1 to 10 do write('Entre com o gabarito da questao ', i,': '); readln(gabarito[i]); end; write('Entre a matricula: '); readln(matricula); while (matricula <> 9999) do begin nota := 0; for i := 1 to 10 do write('Entre com a resposta da questao ', i, ': '); readln(resposta[i]); if (resposta[i] = gabarito[i]) then nota := nota+1; end; writeln('A nota do aluno numero ', matricula,' foi: ',nota); write('Entre a matricula: '); readln(matricula); write('Fim'); readln; end.

9 Matriz Vetor multidimensional Declaração var
identificador:array[vi .. vf] of array[vi .. vf] of tipo; ou, de forma mais simples, identificador:array[vi .. Vf ,vi .. Vf] of tipo;

10 Matriz Program lerMatriz; var matriz: array[1..5, 1..3] of integer;
i,j: integer; begin i := 1; while (i <= 5) do j := 1; while (j <= 3) do write('Entre o valor na posicao ',i,',',j,': '); readln(matriz[i,j]); j := j + 1; end; i := i + 1; end.

11 Matriz Program lerEscreveMatriz;
var matriz: array[1..5, 1..3] of integer; i,j: integer; begin i := 1; while (i <= 5) do j := 1; while (j <= 3) do write('Entre o valor ',i,',',j,': '); readln(matriz[i,j]); j := j + 1; end; i := i + 1; i := 1; while (i <= 5) do begin j := 1; while (j <= 3) do write(matriz[i,j],' '); j := j + 1; end; writeln(' '); i := i + 1; readln; end.

12 Matriz Ler 3 vetores de inteiros a, b e c com 3 elementos cada.
Produzir a matriz m (4x3) tal que: - As 3 primeiras linhas correspondem aos vetores a, b e c. - A 4 linha seja a soma de a+b+c - Imprimir a matriz;

13 Matriz i := 1; while (i <= 3) do begin
write('Entre c na posicao ',i,': '); readln(c[i]); i := i + 1; end; m[1,i] := a[i]; m[2,i] := b[i]; m[3,i] := c[i]; m[4,i] := a[i]+b[i]+c[i]; while (i <= 4) do j := 1; while (j <= 3) do write(m[i,j]:5,' '); j := j + 1; writeln; readln; end. Program somavetor; var a,b,c: array[1..3] of integer; m: array[1..4,1..3] of integer; i,j: integer; begin i := 1; while (i <= 3) do write('Entre a na posicao ',i,': '); readln(a[i]); i := i + 1; end; write('Entre b na posicao ',i,': '); readln(b[i]);


Carregar ppt "Computação Eletrônica"

Apresentações semelhantes


Anúncios Google