For39. Даны целые положительные числа A и B (A < B). Вывести все целые числа от A до B включительно; при этом каждое число должно выводиться столько раз, каково его значение (например, число 3 выводится 3 раза).
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 | program For39; var A, B, i, i2 :Integer; begin Write('Введите A: '); Readln(A); Write('Введите B: '); Readln(B); for i:=A to B do for i2:=1 to i do Writeln(i); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include int main(void) { int a,b; printf("A:"); scanf ("%i", &a); printf("B:"); scanf ("%i", &b); int i,i2; for (i =a; i<=b; ++i){ for (i2=1; i2<=i; ++i2) printf("%i ",i); printf("\n"); } return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int a, b; cout<<"A:"; cin>>a; cout << "B:"; cin >> b; int i, i2; for (i = a; i <= b; ++i) { for (i2 = 1; i2 <= i; ++i2) cout << i <<" "; } return 0; } |
Решения на java:
import java.util.Scanner;
public class for39 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a,b;
System.out.print(«A: «);
a=in.nextInt();
System.out.print(«B: «);
b=in.nextInt();
for (int i = a; i <= b; ++i){ //5
for (int i2 = 1; i2 <= i; ++i2)
System.out.print(i + " ");
System.out.println();
}
}}
Для Python:
n = int(input())
n2 = int(input())
for i in range (n,n2+1):
for u in range(i):
print(i,end=»)
int a,b;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
for (int i = a; i <= b; i++)
{
for(int j = 1; j <=i ; j++)
{
Console.Write($" {i} ");
}
}