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

составьте программу вывода на экран n первых чисел Фибонаги (это числовая последовательность 1,1,2,3,5,8,23,...),которые вычисляются по правилу:а1=1,а2=1,а3=а2+а1,...,аn=аn-1+an-2(после -а- это индексы!!!)pascal ABC

Ответы

Автор ответа: freako
0
Var i,n:integer; a,b:int64; begin read(n); a:=1; b:=1; if (n=1) then write(a) else if (n>=2) then write(a,', ',b); if (n>2) then for i:=1 to n-2 do begin b:=b+a; a:=b-a; write(', ',b); end; End.
Автор ответа: freako
0
Здесь прога покороче, но с массивом.
Var i,n:integer;
a:array[1..100] of int64;
begin
read(n);
a[1]:=1; a[2]:=1;
if (n>2) then
for i:=3 to n do
a[i]:=a[i-1]+a[i-2];
for i:=1 to n do
write(a[i],', ');
End.
Похожие вопросы
Предмет: Математика, автор: vlado201025
Предмет: Английский язык, автор: cheatcheater881
ПОМОГИТЕ ПОЖАЛУЙСТА
Put the verbs in boxes into the present continuous or the present simple

1 Mum cook dinner every night

2You look terrible. What's wrong?

I have a terrible headache

3 you like this dress

yes, a lot hoh much it cost

4Lisa study hard these days

I know she want to pass her exams

5How often you clean your room

once a week

6Pete travel around europe at the moment

7What you do

i talk to Fred

8Betty always wake up late at the weekend

9Hi Olga Anna be there

Sorry, but she sleep now

10 She work on her computer now

CHOOSE THE CORRECT ITEM

1 We visit/visits/are visiting our grandparents every sunday

2Bruce has/is having/have a shower at the moment

3Ben walks/is walking/walk the dog at the moment

4Is she enjoying/does she enjoy/does she enjoys listening to rock music

5John is watching/watch/watches TV every night

6Do parrots lives/live/is living in the jungle

7 They usually go/goes/is going camping every summer

8 Are you looking/looks/look at the holiday photos

PUT THE GIVEN VERBS INTO THE PRESENT SIMPLE OR THE PRESENT CONTINUOUS

1Where's Jim

In the living room He help marry with her homework

2John study Spanish

Yes he go to lessons twice a week

3What you do

Shhhh! i talk on the phone

4Tony and Matt work very hard these days

Yes They want to make some extra money

5What time you have breakfast

7 o'clock The school bus come at 7:30

CORRECT THE MISTAKES IN THE GIVEN SENTECES

1 Alice don't like playing chess

2I works hard at school

3Marry are having dinner at the moment

4 She love talking on the phjne!

5We often eating out on Sunday

6Does They go on trips every weekend

7 I always eat fish Ihate it!

8Does he goes jogging every morning&

9Are you do the washing-up
Предмет: Русский язык, автор: Аноним
Предмет: Математика, автор: Мандариныч