По разделам

 

Решение задачи Series 17


Дано вещественное число B, целое число N и набор из N вещественных чисел, упорядоченных по возрастанию. Вывести элементы
набора вместе с числом B, сохраняя упорядоченность выводимых чисел.

Код (C/C++)

#include <stdio.h>
int main(void)
{
    int n;
    float b,r=1.0;
    printf("N:");
    scanf("%i", &n);
    printf("B:");
    scanf("%f", &b);
    int i,f=1;
    for (i=1; i<=n; ++i){
        printf(">");
        scanf("%f", &r);
        if ((b<=r)&&f){
            printf("%f\n",b);
            f=0;
        }
        printf("%f\n", r);
 
    }
    return 0;
}

Код (Python)

import random

B = random.randrange(1,10)
print("B = ",B)
N = random.randrange(1,20)
print("N = ",N)

for i in range(1,N+1):
    print(i,end="; ")

print()
flag = True
for i in range(1,N+1):
    print(i,end="; ")
    if i <= B and B <= i+1 and flag:
        print("B:",B,end="; ")
        flag = False
									

Код (Pascal)

program Series17;
var
n,i,c:integer;// c - check выводилось ли b
b,num:real;
begin
  Write('N:');
  read(n);
  Write('B:');
  read(b);
  c:=0;// число b пока не выводили
  for i:=1 to n do
    begin
    Write('Num:');
    readln(num);
    if (c=0)and(b<num) then
      begin
      writeln(b);
      c:=1;//число b уже вывели
      end;
    writeln(num);
    end;
  if c=0 then write(b);//если b самое старшее - цикл закончен, но с=0
end.
									




Series. Абрамян
Series 1 Просмотров: 4391
Series 2 Просмотров: 2233
Series 3 Просмотров: 2007
Series 4 Просмотров: 2172
Series 5 Просмотров: 2051
Series 6 Просмотров: 2614
Series 7 Просмотров: 2893
Series 8 Просмотров: 3198
Series 9 Просмотров: 1865
Series 10 Просмотров: 2320
Series 11 Просмотров: 1750
Series 12 Просмотров: 2087
Series 13 Просмотров: 1519
Series 14 Просмотров: 1418
Series 15 Просмотров: 1702
Series 16 Просмотров: 2115
Series 17 Просмотров: 1915
Series 18 Просмотров: 2749
Series 19 Просмотров: 2442
Series 20 Просмотров: 1488
Series 21 Просмотров: 1681
Series 22 Просмотров: 1631
Series 23 Просмотров: 2018
Series 24 Просмотров: 1854
Series 25 Просмотров: 1422
Series 26 Просмотров: 1259
Series 27 Просмотров: 1198
Series 28 Просмотров: 1144
Series 29 Просмотров: 1164
Series 30 Просмотров: 1201
Series 31 Просмотров: 1158
Series 32 Просмотров: 1674
Series 33 Просмотров: 951
Series 34 Просмотров: 996
Series 35 Просмотров: 1379
Series 36 Просмотров: 1486
Series 37 Просмотров: 920
Series 38 Просмотров: 1237
Series 39 Просмотров: 877
Series 40 Просмотров: 1214

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет