The race
participants were assigned numbers from a to b inclusive, and
this information was entered into the computer. Print the athletes’ numbers.
Input. Two positive
integers a and b (a ≤ b ≤ 1000).
Output. Print the athletes’
numbers in ascending order.
Sample input |
Sample output |
3 7 |
3 4 5 6 7 |
loop
Algorithm analysis
Use a for loop. Print the numbers from a to b in ascending
order.
Algorithm
realization
Read the input data.
scanf("%d %d", &a, &b);
Print the athletes’ numbers
in ascending order.
for (i = a; i <= b; i++)
printf("%d ", i);
Java realization
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
for(int i = a; i <= b; i++)
System.out.print(i + " ");
con.close();
}
}
Python realization
Read the input data.
a, b = map(int,input().split())
Print the athletes’ numbers in ascending order.
for i in
range(a, b + 1):
print(i, end=" ")