Предмет: Информатика, автор: mihailzamorin

Задается массив из n натуральных чисел. Найти сумму чисел в которых цифры упорядочены по возрастанию. Язык- паскаль. Задачу сделать надо через функцию

Ответы

Автор ответа: A1dar
0
const
  n = 10;

var
  a: array[1..n] of integer;
  i: integer;

function sum: integer;
var
  tmp, prev, cur, s, i: integer;
  flg: boolean;
begin
  s := 0;
  for i := 1 to n do
  begin
    flg := true;
    tmp := a[i];
    prev := 9;
    cur := 0;
    while tmp > 0 do
    begin
      cur := tmp mod 10;
      if cur > prev then
      begin
        flg := false;
        break;
      end;
      prev := cur;
      tmp := tmp div 10;
    end;
    if flg then inc(s);
  end;
  sum := s;
end;

begin
  writeln('Исходный массив: ');
  for i := 1 to n do
  begin
    a[i] := random(1000);
    write(a[i], ' ');
  end;
  writeln;
  writeln('Ответ: ', sum);
end.

Похожие вопросы
Предмет: Английский язык, автор: sor9292
1 Where...........................your mother work?
a) does b) is c) do
2 …………………….. a new restaurant in our street,
a) There be b) There is c) There has
3 Why...........................always angry with me?
a) are you b) you are c) do you
4 ..........................................
a) It's got b) Its got c) There's got
5 ………………………………………..a museum in your town?
a) Is b) Is it c) Is there
6 The...........................videos are on that shelf.
a) childrens b) children's c) childrens'
7 This computer is …………………........
.............. a) mine b) my c) mine's
8 How many people.........................in your class?
a) are there b) there are c) have got
9 My father teaches at a...........................school in Warsaw.
a) boy's b) boys' c) boys
10...................................
a) There isn’t b) It hasn't c) There hasn't
11 Can I read the...........................?
a) end of the letter b) letter's end c) end's letter
12 What time does the film...........................?
a) starting b) starts c) start
13 In the centre...........................three good music shops.
a) they are b) there are c) they're
14 My parents……………………….like dancing.
a) don't b) aren't c) doesn't
15 ...........................two Ts in the name ANITA.
a) They're not b) There aren't c) Aren't
16 Where is...........................ticket?
a) there b) they're c) their
17 ...........................T-shirt is on the bed.
a) He's b) His c) It's
18 ...........................got statues on the roof.
a) It is b) It has c) There's
19...........................sisters live in Canada.
a) Your mothers' b) You're mothers c) Your mother's
20 ...........................easy to remember my phone number.
a) Is b) Its c) It's
Предмет: Биология, автор: Аноним