Другие языки программирования и технологии
Помогите пожалуйста решить задачи по программированию. P.S: задачи по паскалю.
1. Найти кол-во нулей в записи заданного числа а. 2. Даны два числа. Верно ли, что в записи этих двух чисел используются все цифры. 3. Описать функцию Even (К) логического типа, возвращающую true, если целый параметр К является четным, и false в противном случае. С ее помощью найти кол-во четных чисел в наборе из 10 целых чисел.
1. Program P1;
var a,i,c:integer; //(ты не уточнил какого типа число a, так что делаю его integer)
s:string;
begin
writeln('Введите а');
readln(a);
c:=0;
s:=inttostr(a); //функция inttostr автоматически переводит целые числа в строку. так легче искать
for i:=1 to length(s) do
begin
if s=0 then c:=c+1;
end;
writln('Количество нулей = ',c);
end.
2. Program P2;
var m: array [1..10] of integer;
a,b,i:integer;
s:string;
begin
writeln('Введите а');
readln(a);
writeln('Введите b');
readln(b);
for i:=1 to 10 do
a:=54; (заношу в весь массив какое-нибудь чесло большее 9. Зачем объясню позже)
s:=inttostr(a);
for i:=1 to length(s) do
begin
if s=0 then
m[1]:=0;
if s=1 then
m[2]:=1;
if s=2 then
m[3]:=2;
if s=3 then
m[4]:=3;
if s=4 then
m[5]:=4;
if s=5 then
m[6]:=5;
if s=6 then
m[7]:=6;
if s=7 then
m[8]:=7;
if s=8 then
m[9]:=8;
if s=9 then
m[10]:=9;
end;
s:=inttostr(b);
for i:=1 to length(s) do
begin
if s=0 then
m[1]:=0;
if s=1 then
m[2]:=1;
if s=2 then
m[3]:=2;
if s=3 then
m[4]:=3;
if s=4 then
m[5]:=4;
if s=5 then
m[6]:=5;
if s=6 then
m[7]:=6;
if s=7 then
m[8]:=7;
if s=8 then
m[9]:=8;
if s=9 then
m[10]:=9;
end;
if (m[1]=0) and (m[2]=1) and (m[3]=2) and (m[4]=3) and (m[5]=4) and (m[6]=5) and (m[7]=6) and (m[8]=7) and (m[9]=8) and (m[10]=9) then //(вот для чего использовались числа большие 9 в массиве. если бы мы использовали от 1 до 9, то не всегда при сравнение выдавался бы правильный результат)
writeln('Используються все числа')
else
writeln('Используються не все числа');
end.
3.program P3;
var a: array [1..10] of integer;
i,j: integer;
begin
function Even(k:integer):boolean;
begin
if k mod 2=0 then Even:=true
else Even:=false;
end;
writekn('Введите набор нажимая Enter после ввода каждого числа');
for i:=1 to 10 do
readln(a);
j:=0;
for i:=1 to 10 do
begin
Even(a);
if Even=true then j:=j+1;
end;
writeln('Количество четных чисел = ',j);
end.
var a,i,c:integer; //(ты не уточнил какого типа число a, так что делаю его integer)
s:string;
begin
writeln('Введите а');
readln(a);
c:=0;
s:=inttostr(a); //функция inttostr автоматически переводит целые числа в строку. так легче искать
for i:=1 to length(s) do
begin
if s=0 then c:=c+1;
end;
writln('Количество нулей = ',c);
end.
2. Program P2;
var m: array [1..10] of integer;
a,b,i:integer;
s:string;
begin
writeln('Введите а');
readln(a);
writeln('Введите b');
readln(b);
for i:=1 to 10 do
a:=54; (заношу в весь массив какое-нибудь чесло большее 9. Зачем объясню позже)
s:=inttostr(a);
for i:=1 to length(s) do
begin
if s=0 then
m[1]:=0;
if s=1 then
m[2]:=1;
if s=2 then
m[3]:=2;
if s=3 then
m[4]:=3;
if s=4 then
m[5]:=4;
if s=5 then
m[6]:=5;
if s=6 then
m[7]:=6;
if s=7 then
m[8]:=7;
if s=8 then
m[9]:=8;
if s=9 then
m[10]:=9;
end;
s:=inttostr(b);
for i:=1 to length(s) do
begin
if s=0 then
m[1]:=0;
if s=1 then
m[2]:=1;
if s=2 then
m[3]:=2;
if s=3 then
m[4]:=3;
if s=4 then
m[5]:=4;
if s=5 then
m[6]:=5;
if s=6 then
m[7]:=6;
if s=7 then
m[8]:=7;
if s=8 then
m[9]:=8;
if s=9 then
m[10]:=9;
end;
if (m[1]=0) and (m[2]=1) and (m[3]=2) and (m[4]=3) and (m[5]=4) and (m[6]=5) and (m[7]=6) and (m[8]=7) and (m[9]=8) and (m[10]=9) then //(вот для чего использовались числа большие 9 в массиве. если бы мы использовали от 1 до 9, то не всегда при сравнение выдавался бы правильный результат)
writeln('Используються все числа')
else
writeln('Используються не все числа');
end.
3.program P3;
var a: array [1..10] of integer;
i,j: integer;
begin
function Even(k:integer):boolean;
begin
if k mod 2=0 then Even:=true
else Even:=false;
end;
writekn('Введите набор нажимая Enter после ввода каждого числа');
for i:=1 to 10 do
readln(a);
j:=0;
for i:=1 to 10 do
begin
Even(a);
if Even=true then j:=j+1;
end;
writeln('Количество четных чисел = ',j);
end.
var count,x:integer;
begin
read(x);
while (x>0) do
begin
if (x mod 10 = 0) then
count:=count+1;
x:=x div 10;
end;
writeln(count);
end.
var nb:set of byte;
x:integer;
begin
read(x);
nb:=[];
while x>0 do
begin
nb:=nb + [x mod 10];
x:=x div 10;
end;
if ([0..9] in nb) then
writeln('OK');
else writeln('Fail');
end;
var n,j,count:integer;
x:array[1..10] of integer;
function Even(x:integer):boolean;
begin
if (x mod 2 = 0) then Even:=true;
else Even:=false;
end;
begin
count:=0;
read(N);
for j:=1 to N do
read(x[j]);
for j:=1 to N do
if (Even(x[j])) then count:=count+1;
writeln(count);
end.
begin
read(x);
while (x>0) do
begin
if (x mod 10 = 0) then
count:=count+1;
x:=x div 10;
end;
writeln(count);
end.
var nb:set of byte;
x:integer;
begin
read(x);
nb:=[];
while x>0 do
begin
nb:=nb + [x mod 10];
x:=x div 10;
end;
if ([0..9] in nb) then
writeln('OK');
else writeln('Fail');
end;
var n,j,count:integer;
x:array[1..10] of integer;
function Even(x:integer):boolean;
begin
if (x mod 2 = 0) then Even:=true;
else Even:=false;
end;
begin
count:=0;
read(N);
for j:=1 to N do
read(x[j]);
for j:=1 to N do
if (Even(x[j])) then count:=count+1;
writeln(count);
end.
Похожие вопросы
- Помогите пожалуйста решить задачу по программированию. В чем я ошибаюсь?
- Помогите пожалуйста решить задачу по программированию (язык программирования СИ)
- Помогите пожалуйста решить задачу по программированию или напишите, как удалить подряд стоящие точки. (Си, Си++ Билдер)
- Pascal. Помогите пожалуйста решить задачу в паскале !
- Помогите,пожалуйста,решить задачу в Паскале.
- Помогите,пожалуйста,решить задачу на двумерные массивы,в паскале.(задача вн.)Спасибо.
- Помогите пожалуйста решить задачу в паскале.
- помогите пожалуйста!!!!решить задачу на паскале...
- помогите пожалуйста решить задачи в паскале очень нужно!
- Помогите пожалуйста решить задачу в Паскале!