Construa um algoritmo para gerar aleatório 1000 números, calcular o somatório, a média, o maior e o menor número gerado.
Program 1000_numeros;
var
x,menor,maior,n: integer;
media:real;
Begin
maior:=0;
menor:=1001;
for x:=1 to 1000 do
begin
delay(3);
n:=random(1001);
Writeln(n);
if n
menor:=n;
if n>maior then
maior:=n;
media:=media+n;
end;
Writeln('Maior numero ',maior);
Writeln('Menor numero: ',menor);
Writeln('Somatorio ',media:7:1);
Writeln('Media ',media/1000:4:2);
Writeln(' ');
Readln;
End.
quarta-feira, 22 de setembro de 2010
Exercicio -Numeros de 1 a 100
Construa um algoritmo para que o computador gere dez números aleatórios entre 1 e 100. A seguir escreva a quantidade de números gerados acima de 50 e abaixo de 50.
Program numeros_1_100;
var
x,y,z,n:integer;
Begin
y:=0;
x:=0;
for z:=1 to 10 do
begin
delay(500);
n:=random(100);
Writeln(n);
if n<50>
x:=x+1;
if n>50 then
y:=y+1;
end;
Writeln('Numeros Abaixo:',x);
Writeln('Numeros Acima:',y);
Readln;
End.
Program numeros_1_100;
var
x,y,z,n:integer;
Begin
y:=0;
x:=0;
for z:=1 to 10 do
begin
delay(500);
n:=random(100);
Writeln(n);
if n<50>
x:=x+1;
if n>50 then
y:=y+1;
end;
Writeln('Numeros Abaixo:',x);
Writeln('Numeros Acima:',y);
Readln;
End.
Exercicio -Peso maior
Faça um algoritmo e a seguir passe-o para pascal que leia o nome e peso de 10 pessoas e a seguir calcule o maior peso, o mais leve, e a média de peso. Escreva o nome da pessoa com maior peso.
Program Peso ;
VAR
nome, nmaior, nmenor, f : integer;
peso, pmaior, pmenor, pmedia : real;
Begin
for f := 1 to 10 do
begin
Writeln ('Escreva seu nome');
readln (nome);
Writeln ('Escreva seu peso');
readln (peso);
end;
pmenor := peso;
if (pmenor <= peso) then
writeln ('o menor peso é,');
writeln (pmenor);
Writeln ('o nome é');
writeln (nome);
if (pmaior >= peso) then
writeln ('o maior peso é');
writeln (pmaior);
writeln ('o nome é');
writeln (nome);
pmedia := (peso + peso) / 10;
writeln ('a media é,');
writeln (pmedia);
End.
Program Peso ;
VAR
nome, nmaior, nmenor, f : integer;
peso, pmaior, pmenor, pmedia : real;
Begin
for f := 1 to 10 do
begin
Writeln ('Escreva seu nome');
readln (nome);
Writeln ('Escreva seu peso');
readln (peso);
end;
pmenor := peso;
if (pmenor <= peso) then
writeln ('o menor peso é,');
writeln (pmenor);
Writeln ('o nome é');
writeln (nome);
if (pmaior >= peso) then
writeln ('o maior peso é');
writeln (pmaior);
writeln ('o nome é');
writeln (nome);
pmedia := (peso + peso) / 10;
writeln ('a media é,');
writeln (pmedia);
End.
Exercicio Kneippopolis
Faca um programa para apontar os resultados de uma pesquisa eleitoral para presidente da republica de Kneippopolis, o mais novo pais da America do Sul. Os candidatos são: Zico, Ricardo Kneipp, Obina e Geninho. Escreva o total e o percentual de votos de cada candidato. A seguir escreva o nome do novo presidente do pais com maior IDH do planeta.
Program Pzim ; KNEIPOPOLIS
var
voto:char;
cont,somaZ,somaR,somaO,somaG,somaN,maior:integer;
percZ,percR,percO,percG:real;
nomepres:string;
Begin
maior:=0;
writeln('Pesquisa eleitoral para presidente da república de Kneippópolis');
writeln;
writeln('Os candidatos são: Zico, Ricardo Kneipp, Obina e Geninho');
writeln;
for cont:=1 to 10 do
begin
writeln('Dê seu voto:Zico - Z, Ricardo Kneipp - R, Obina - O, Geninho - G');
read(voto);
clrscr;
case voto of
'Z' : somaZ:= somaZ+1;
'R' : somaR:= somaR+1;
'O' : somaO:= somaO+1;
'G' : somaG:= somaG+1;
'z' : somaZ:= somaZ+1;
'r' : somaR:= somaR+1;
'o' : somaO:= somaO+1;
'g' : somaG:= somaG+1;
else
writeln('Seu voto foi invalido');
end;
if (somaZ>maior) then
begin
maior:=somaZ;
nomepres:='Zico';
end;
if (somaR>maior) then
begin
maior:=somaR;
nomepres:='Ricardo Keneipp';
end;
if (somaO>maior) then
Begin
maior:=somaO;
nomepres:='Obina';
end;
if (somaG>maior) then
begin
maior:=somaG;
nomepres:='Geninho';
end;
end;
percZ:=(somaZ/10)*100;
percR:=(somaR/10)*100;
percO:=(somaO/10)*100;
percG:=(somaG/10)*100;
clrscr;
writeln('O percentual de fotos recebidos pelo candidato Zico foi:',percZ:2:2,'% e o total de votos foi:',somaZ);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Ricardo Kneipp foi:',percR:2:2,'% e o total de votos foi:',somaR);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Obina foi:',percO:2:2,'% e o total de votos foi:',somaO);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Geninho foi:',percG:2:2,'% e o total de votos foi:',somaG);
writeln;
Writeln('O presidente com mais votos foi o ',nomepres,', com ',maior,' votos.');
End.
Program Pzim ; KNEIPOPOLIS
var
voto:char;
cont,somaZ,somaR,somaO,somaG,somaN,maior:integer;
percZ,percR,percO,percG:real;
nomepres:string;
Begin
maior:=0;
writeln('Pesquisa eleitoral para presidente da república de Kneippópolis');
writeln;
writeln('Os candidatos são: Zico, Ricardo Kneipp, Obina e Geninho');
writeln;
for cont:=1 to 10 do
begin
writeln('Dê seu voto:Zico - Z, Ricardo Kneipp - R, Obina - O, Geninho - G');
read(voto);
clrscr;
case voto of
'Z' : somaZ:= somaZ+1;
'R' : somaR:= somaR+1;
'O' : somaO:= somaO+1;
'G' : somaG:= somaG+1;
'z' : somaZ:= somaZ+1;
'r' : somaR:= somaR+1;
'o' : somaO:= somaO+1;
'g' : somaG:= somaG+1;
else
writeln('Seu voto foi invalido');
end;
if (somaZ>maior) then
begin
maior:=somaZ;
nomepres:='Zico';
end;
if (somaR>maior) then
begin
maior:=somaR;
nomepres:='Ricardo Keneipp';
end;
if (somaO>maior) then
Begin
maior:=somaO;
nomepres:='Obina';
end;
if (somaG>maior) then
begin
maior:=somaG;
nomepres:='Geninho';
end;
end;
percZ:=(somaZ/10)*100;
percR:=(somaR/10)*100;
percO:=(somaO/10)*100;
percG:=(somaG/10)*100;
clrscr;
writeln('O percentual de fotos recebidos pelo candidato Zico foi:',percZ:2:2,'% e o total de votos foi:',somaZ);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Ricardo Kneipp foi:',percR:2:2,'% e o total de votos foi:',somaR);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Obina foi:',percO:2:2,'% e o total de votos foi:',somaO);
writeln;
writeln('O percentual de fotos recebidos pelo candidato Geninho foi:',percG:2:2,'% e o total de votos foi:',somaG);
writeln;
Writeln('O presidente com mais votos foi o ',nomepres,', com ',maior,' votos.');
End.
Exercicio 06
6 inclua a posição do maior e do menor valor encontrado.
Program ;
var
maior, menor, soma, cont,con: integer;
media :real;
vetor: array[1..50] of integer;
pmaior
Begin
maior:=0;
menor:=101;
soma:=0;
cont:=0;
for cont:=1 to 50 do
begin
randomize;
vetor[cont] := random(99)+1;
if(vetor[cont] > maior)then
maior := vetor[cont];
if(vetor[cont] < menor)then
menor := vetor[cont];
soma:= soma + vetor[cont];
end;
media:= soma/50;
for con:=1 to 50 do
write(' [',vetor[con],'] ');
writeln('');
writeln('');
writeln('A media dos numeros e ',media);
writeln('O maior numero e ',maior);
writeln('O menor numero e ',menor);
End.
Program ;
var
maior, menor, soma, cont,con: integer;
media :real;
vetor: array[1..50] of integer;
pmaior
Begin
maior:=0;
menor:=101;
soma:=0;
cont:=0;
for cont:=1 to 50 do
begin
randomize;
vetor[cont] := random(99)+1;
if(vetor[cont] > maior)then
maior := vetor[cont];
if(vetor[cont] < menor)then
menor := vetor[cont];
soma:= soma + vetor[cont];
end;
media:= soma/50;
for con:=1 to 50 do
write(' [',vetor[con],'] ');
writeln('');
writeln('');
writeln('A media dos numeros e ',media);
writeln('O maior numero e ',maior);
writeln('O menor numero e ',menor);
End.
Exercicio 02
2 Faça um programa para ler 20 numeros, calcular a media o maior e o menor número.
Program Questao2 ;
Var
num, maior, menor, cont, soma : integer;
media : real;
vetor:array[1..20]of integer;
Begin
cont:=0;
for cont:=1 to 3 do
begin
Writeln ('Escreva o numero');
readln (vetor[cont]);
soma:=vetor[cont]+soma;
if (vetor[cont] >= maior) then
maior:=vetor[cont];
if (vetor[cont]<= menor) then
menor:=vetor[cont];
end;
media:=soma/3;
Writeln ('O maior numero e ', maior);
writeln ('O menor numero e ', menor);
writeln ('A media é ', media);
End.
Program Questao2 ;
Var
num, maior, menor, cont, soma : integer;
media : real;
vetor:array[1..20]of integer;
Begin
cont:=0;
for cont:=1 to 3 do
begin
Writeln ('Escreva o numero');
readln (vetor[cont]);
soma:=vetor[cont]+soma;
if (vetor[cont] >= maior) then
maior:=vetor[cont];
if (vetor[cont]<= menor) then
menor:=vetor[cont];
end;
media:=soma/3;
Writeln ('O maior numero e ', maior);
writeln ('O menor numero e ', menor);
writeln ('A media é ', media);
End.
Exercicio 01
1 Faça um programa para ler 10 numeros e escrever a soma.
Program Questao2 ;
Var
num, cont, soma : integer;
vetor:array[1..10]of integer;
Begin
cont:=0;
for cont:=1 to 10 do
begin
Writeln ('Escreva o numero');
readln (vetor[cont]);
soma:=vetor[cont]+soma;
end;
writeln ('A soma é ', soma);
End.
Program Questao2 ;
Var
num, cont, soma : integer;
vetor:array[1..10]of integer;
Begin
cont:=0;
for cont:=1 to 10 do
begin
Writeln ('Escreva o numero');
readln (vetor[cont]);
soma:=vetor[cont]+soma;
end;
writeln ('A soma é ', soma);
End.
terça-feira, 21 de setembro de 2010
Exercicio 07
7 - Escreva um algoritimo que leia um vetor G de 20 elementos caractere que represente....
Program ler_20_numeros ;
VAR
certa,soma, cont, cont1,alunos : integer;
G:array[1..20]of char;
R:array[1..20]of char;
Begin
soma:=0;
for cont1:=1 to 5 do
begin
writeln ('digite a resposta da questao ', cont1);
readln (G[cont1]);
end;
writeln ('Gabarito inserido');
writeln;
for alunos:=1 to 3 do
begin
for cont:=1 to 5 do
begin
writeln ('ALUNO [ ',alunos,' ]Digite a resposta ',cont);
readln (R[cont]);
if (R[cont] = G[cont]) then
soma:=soma+1;
end;
if (soma>=3) then
Writeln ('Aluno ',alunos,' aprovado')
else
Writeln ('Aluno ',alunos,' reprovado');
Writeln;
Writeln;
soma:=0;
Writeln('------------------------------------');
end;
End.
Program ler_20_numeros ;
VAR
certa,soma, cont, cont1,alunos : integer;
G:array[1..20]of char;
R:array[1..20]of char;
Begin
soma:=0;
for cont1:=1 to 5 do
begin
writeln ('digite a resposta da questao ', cont1);
readln (G[cont1]);
end;
writeln ('Gabarito inserido');
writeln;
for alunos:=1 to 3 do
begin
for cont:=1 to 5 do
begin
writeln ('ALUNO [ ',alunos,' ]Digite a resposta ',cont);
readln (R[cont]);
if (R[cont] = G[cont]) then
soma:=soma+1;
end;
if (soma>=3) then
Writeln ('Aluno ',alunos,' aprovado')
else
Writeln ('Aluno ',alunos,' reprovado');
Writeln;
Writeln;
soma:=0;
Writeln('------------------------------------');
end;
End.
Exercicio 05
5 - Excreva um algoritimo que leia um vetor de 80 elementos inteiros. encontre e mostre o menos elemento e sua posição no vetor.
Program_posição_no_vetor ;
var
num:array[1..5]of integer;
cont, cont2, menor:integer;
menorNum:array[1..5]of integer;
Begin
cont:=0;
menor:=1000;
for cont:=1 to 5 do
begin
writeln('Informe um número:',cont);
readln(num[cont]);
if num[cont]
begin
cont2:=cont2+1;
menor:=num[cont];
menorNum[cont2]:=menor;
end;
end;
writeln('O menor número é: ', menor,' e sua posiçao no vetor é: ',cont2);
End.
Program_posição_no_vetor ;
var
num:array[1..5]of integer;
cont, cont2, menor:integer;
menorNum:array[1..5]of integer;
Begin
cont:=0;
menor:=1000;
for cont:=1 to 5 do
begin
writeln('Informe um número:',cont);
readln(num[cont]);
if num[cont]
begin
cont2:=cont2+1;
menor:=num[cont];
menorNum[cont2]:=menor;
end;
end;
writeln('O menor número é: ', menor,' e sua posiçao no vetor é: ',cont2);
End.
Exercicio 04
4 - Escreva um algoritimo que leia um vetor de 50 posições de numeros inteiros e mostre somente os positivos.
Program numeros positivos ;
var
num:array[1..5]of integer;
cont, i:integer;
positivo:array[1..5]of integer;
Begin
i:= 0;
for cont:=1 to 5 do
begin
writeln('Informe um número:');
readln(num[cont]);
if num[cont]>0 then
begin
i:= i + 1;
positivo[i] := num[cont];
end;
end;
for cont:=1 to i do
writeln('Os números positivos sao:',positivo[cont]);
End
Program numeros positivos ;
var
num:array[1..5]of integer;
cont, i:integer;
positivo:array[1..5]of integer;
Begin
i:= 0;
for cont:=1 to 5 do
begin
writeln('Informe um número:');
readln(num[cont]);
if num[cont]>0 then
begin
i:= i + 1;
positivo[i] := num[cont];
end;
end;
for cont:=1 to i do
writeln('Os números positivos sao:',positivo[cont]);
End
Exercicio 03
3 - Prepare um programa para calcular as notas da P1, P2 e P3 de 10 alunos, escreva a media final de cada aluno e escreva o total de pessoas aprovadas e reprovadas.
Program notas ;
var
P1: array[1..10]of real;
P2: array[1..10]of real;
P3: array[1..10]of real;
media,soma:real;
cont:integer;
Begin
for cont:= 1 to 10 do
begin
writeln('1ª nota:');
read(P1[cont]);
writeln('2ª nota:');
read(P2[cont]);
writeln('3ª nota:');
read(P3[cont]);
soma:=(P1[cont]+P2[cont]+P3[cont]);
media[cont]:=soma/3;
writeln('A media do aluno é:',media);
end;
End.
Program notas ;
var
P1: array[1..10]of real;
P2: array[1..10]of real;
P3: array[1..10]of real;
media,soma:real;
cont:integer;
Begin
for cont:= 1 to 10 do
begin
writeln('1ª nota:');
read(P1[cont]);
writeln('2ª nota:');
read(P2[cont]);
writeln('3ª nota:');
read(P3[cont]);
soma:=(P1[cont]+P2[cont]+P3[cont]);
media[cont]:=soma/3;
writeln('A media do aluno é:',media);
end;
End.
Assinar:
Postagens (Atom)