Basics
(перенаправлено с «Основы»)
Перейти к навигации
Перейти к поиску
Pascal.ABC
1 Program Basics;
2 var
3 i, k, sum : integer;
4 div3, div5 : string;
5 NumberIsOk : boolean;
6 Begin
7 Writeln('Добро пожаловать!');
8 repeat
9 Writeln('Введите число от 1 до 20!');
10 Readln(i);
11 NumberIsOK := true;
12 if ((i < 1) or (i > 20)) then
13 NumberIsOK := false;
14 until (NumberIsOK);
15
16 for var j := 1 to i do
17 begin
18 div3 := '';
19 div5 := '';
20 if (j mod 3 = 0) then
21 Begin
22 div3 := 'Fizz';
23 end;
24
25 if (j mod 5 = 0) then
26 Begin
27 div5 := 'Buzz';
28 end;
29
30 Writeln(j + ' = ' + div3 + div5);
31 end;
32
33 k := 1;
34 sum := 0;
35 Repeat
36 sum := sum + k;
37 k := k + 1;
38 until k > i;
39 Writeln('Sum = ' + sum);
40 end.
Javascript
index.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Basics</title>
6 <script type="application/javascript" src="script.js"></script>
7 </head>
8 <body>
9
10 </body>
11 </html>
script.js
1 var i = 0;
2 do {
3 i = prompt('Please enter a number between 1 and 20.');
4 i = parseInt(i);
5 } while(!Number.isInteger(i) || i < 1 || i > 20);
6
7 var message = '';
8 var div3, div5;
9 for (var j = 1; j <= i; j++) {
10 div3 = '';
11 div5 = '';
12 if (j % 3 === 0)
13 {
14 div3 += 'Fizz';
15 }
16
17 if (j % 5 === 0)
18 {
19 div5 += 'Buzz';
20 }
21
22 message += j + ' = ' + div3 + div5 + '\n';
23 }
24
25 var k = 1;
26 var sum = 0;
27 do {
28 sum += k;
29 k++;
30 } while (k <= i);
31
32 message += 'Sum = ' + sum;
33
34 alert(message);
C
1 #include<stdio.h>
2
3 int main()
4 {
5 printf("Hello!\n");
6
7 int i;
8 do {
9 printf("Please enter a number from 1 to 20.\n");
10 scanf_s("%d", &i);
11 } while (i < 1 || i > 20);
12
13
14 for (int j = 1; j <= i; j++) {
15 printf("%d ", j);
16 if (j % 3 == 0)
17 {
18 printf("Fizz");
19 }
20
21 if (j % 5 == 0)
22 {
23 printf("Buzz");
24 }
25
26 printf("\n");
27 }
28
29 int k = 1;
30 int sum = 0;
31 do {
32 sum += k;
33 k++;
34 } while (k <= i);
35
36 printf("Sum = %d\n", sum);
37
38 return 0;
39 }