optikmir
?>

плзДана непустая последовательность положительных целых чисел а1 , а2 , … оканчивающаяся нулем. Получить a1, a1*a2, a1*a2*a3, ..., 0 написать программу на с++

Информатика

Ответы

ЕленаГерасимова
Выводит 2 строки: Сам массив(20 элементов от 10 до 99) и строку с номерами элементов кратных 7, если таковых элементов нет, то пишет No elements.

program test;
uses crt;
const
  t:boolean=false;
var
  arr:array[1..20] of integer;
  i:integer;
begin
  randomize;
  clrscr;
  for i:=1 to 20 do
    begin
      arr[i]:=random(90)+10;
      write(arr[i],' ');
    end;
  writeln;
  for i:=1 to 20 do
    if arr[i] mod 7 = 0 then
      begin
        write(i,' ');
        t:=true;
      end;
  if t=false then
     write('No elements');
end.
mmctriitsk
Я здесь и для *(умножения тоже сделал)
program gt;
label 1;
var a:string;
i,l,s,s2,s3,j:longint;
begin
read(a);l:=length(a);s:=0;s2:=0;
for i:=1 to l do
begin
if (a[i]='+')or(a[i]='-')or(a[i]='*')then goto 1;
end;
1:
for j:=1 to i-1 do
begin
if a[j]='1' then s:=s*10+1;
if a[j]='2' then s:=s*10+2;
if a[j]='3' then s:=s*10+3;
if a[j]='4' then s:=s*10+4;
if a[j]='5' then s:=s*10+5;
if a[j]='6' then s:=s*10+6;
if a[j]='7' then s:=s*10+7;
if a[j]='8' then s:=s*10+8;
if a[j]='9' then s:=s*10+9;
if a[j]='0' then s:=s*10+0;
end;
for j:=i+1 to l do
begin
if a[j]='1' then s2:=s2*10+1;
if a[j]='2' then s2:=s2*10+2;
if a[j]='3' then s2:=s2*10+3;
if a[j]='4' then s2:=s2*10+4;
if a[j]='5' then s2:=s2*10+5;
if a[j]='6' then s2:=s2*10+6;
if a[j]='7' then s2:=s2*10+7;
if a[j]='8' then s2:=s2*10+8;
if a[j]='9' then s2:=s2*10+9;
if a[j]='0' then s2:=s2*10+0;
end;
if a[i]='+' then s3:=s+s2;
if a[i]='-' then s3:=s-s2;
if a[i]='*' then s3:=s*s2;
writeln(s3);
end.
2)более проще
program gt;
label 1;
var a:string;
i,l,s,s2,s3,j:longint;
begin
read(a);l:=length(a);s:=0;s2:=0;
for i:=1 to l do
begin
if (a[i]='+')or(a[i]='-')or(a[i]='*')then goto 1;
end;
1:
for j:=1 to i-1 do
begin
s:=s*10+ord(a[j])-48;
end;
for j:=i+1 to l do
begin
s2:=s2*10+ord(a[j])-48;
end;
if a[i]='+' then s3:=s+s2;
if a[i]='-' then s3:=s-s2;
if a[i]='*' then s3:=s*s2;
writeln(s3);
end.

Ответить на вопрос

Поделитесь своими знаниями, ответьте на вопрос:

плзДана непустая последовательность положительных целых чисел а1 , а2 , … оканчивающаяся нулем. Получить a1, a1*a2, a1*a2*a3, ..., 0 написать программу на с++
Ваше имя (никнейм)*
Email*
Комментарий*

Популярные вопросы в разделе

Vikkitrip
Igor1406
dream2366
Bella Sergei
Chernaya
vladai2
k-alexey9
Andreevich440
Светлана константин
ГармаеваЕкатерина1637
frsergeysavenok
lzelenyi5
horst58
Klicheva_Ermachenkova1536
Avolohova