For2. Даны два целых числа A и B (A < B). Вывести в порядке возрастания все целые числа, расположенные между A и B (включая сами числа A и B), а также количество N этих чисел.
Решение Python
1 2 3 4 5 6 7 8 9 10 11 12 | # Input integers A and B A = int(input("Enter the value of A: ")) B = int(input("Enter the value of B: ")) # Calculate the count of numbers between A and B count = B - A + 1 # Output the numbers and their count print(f"The numbers between {A} and {B} are:") for num in range(A, B + 1): print(num, end=" ") print(f"\nTotal count of numbers: {count}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 | program For2; var A,B, i:Integer; begin Write('Введите A: '); Readln(A); Write('Введите B: '); Readln(B); For i:=0 to B-A do Writeln(A+i); Writeln(B-A+1); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> int main(void) { int a, b; printf("A:"); scanf ("%i", &a); printf("B:"); scanf ("%i", &b); int i; for (i = a; i<=b; ++i) printf("%i\n",i); printf("N: %i\n", b-a+1); 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() { int a, b; cout << "A:"; cin >> a; cout << "B:"; cin >> b; int i; for (i = a; i<=b; ++i) cout << i << endl; cout << "N:" << b-a+1 << endl; return 0; } |
Решение C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.Write("a:"); int a = Convert.ToInt32(Console.ReadLine()); Console.Write("b:"); int b = Convert.ToInt32(Console.ReadLine()); for (int i = a; i <= b; i++) Console.WriteLine(i); int n = b - a + 1; Console.WriteLine("n=" + n ); Console.ReadKey(); } } } |
>
Решение Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package abramyan; import java.util.Scanner; public class Abramyan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("a:"); int a = in.nextInt(); System.out.print("b:"); int b = in.nextInt(); for (int i = a; i <= b; i++) System.out.println(i); int n = b - a + 1; System.out.println("n=" + n ); in.close(); } } |
Python
#for2
a=int(input())
b=int(input())
n=0
for i in range(a,b+1):
n+=1
print(i)
print(n)
На JavaScript е как будет
kotlin:
fun main() {
var A = 5
var B = 10
for (i in A..B){
println(i)
}
}
Kotlin:
fun main() {
var A = 20
var B = 30
for (i in A..B){
println(i)
}
var n = B — A + 1
println(n)
}
//извиняюсь, правильнее так
Kotlin:
fun main() {
var A = 20
var B = 30
for (i in A..B){
println(i)
}
var n = B-A+1
println(n)
}
// еще раз извиняюсь, правильнее так 😀
//SWIFT
func main (){
}
var A = 20
var B = 30
for i in A…B{
print(i)
}
var n = B — A + 1
print(n)
С#:
using System;
using System.IO;
public class Example
{
public static void Main()
{
Console.Write(«Введите число А = «);
int a = Convert.ToInt32(Console.ReadLine());
Console.Write(«Введите число В = «);
int b = Convert.ToInt32(Console.ReadLine());
int i;
for (i = 0; i <= (b — a); i++)
{
Console.WriteLine(a + i);
}
Console.WriteLine(i);
Console.ReadKey();
}
}
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int n = 0;
for (int i = a; i<=b; i++) {
System.out.println(i + " ");
n = b — a + 1;
}
System.out.println(n);