For4. Дано вещественное число — цена 1 кг конфет. Вывести стоимость 1, 2, …, 10 кг конфет.
Решение Python
1 2 3 4 5 6 7 8 | # Input the price of 1 kg of sweets price_per_kg = float(input("Enter the price of 1 kg of sweets: ")) # Calculate and output the cost of 1 to 10 kg of sweets print("Cost of sweets:") for kg in range(1, 11): cost = kg * price_per_kg print(f"{kg} kg: {cost}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 | program For4; var C:Real; i:Integer; begin Write('Введите стоимость 1 кг конфет: '); Readln(C); Writeln('Введите стоимость конфет: '); For i:=1 to 10 do Writeln(i,'кг: ',i*C); end. |
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main(void) { float c; printf("Cost:"); scanf ("%f", &c); int i; for (i = 1; i<=10; ++i) printf("%i kg = %f \n ",i,c*i); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 | #include <iostream> using namespace std; int main(){ float c; cout << "Cost:"; cin >> c; for (int i = 1; i<=10; ++i) cout << i << " kg = " << c*i << endl; return 0; } |
Решение C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.Write("Price="); double c = Convert.ToDouble(Console.ReadLine()); for (int i = 1; i <= 10; ++i) Console.WriteLine($"{i} kg = {c*i}"); Console.ReadKey(); } } } |
>
Решение Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package abramyan; import java.util.Scanner; public class Abramyan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Price="); double c = in.nextDouble(); for (int i = 1; i <= 10; ++i) System.out.println(i + "kg = " + c*i); in.close(); } } |
kotlin:
fun main() {
var A = 5
for (i in 1..10){
println(«$i) $i»+»kg=» + i*A)
}
}
Python
a=flout(input(«Введите цену»))
count=0
while count<=2
print(count "цена за кг")count*a)
count+=0,2
//kotlin
fun main(){
var k=25
for(i in 1..10){
println(i*k)
}
}
//SWIFT
var a: Int = 25
for iteam in 1…10{
print(iteam * a)
}
C#:
using System;
public class Example
{
public static void Main()
{
Console.Write(«Введите стоимость 1 кг. конфет = «);
double a = Convert.ToDouble(Console.ReadLine());
for (int i = 1; i<=10; ++i)
{
Console.WriteLine("{0} кг. конфет стоит {1} руб. ",i,a * i);
}
Console.ReadKey();
}
}
Scanner sc = new Scanner(System.in);
double sum = sc.nextDouble();
for(int n = 1; n<=10; n++){
System.out.println(n+"кг="+sum*n);
}
a = int(input(‘enter the price: ‘))
c = 0
for i in range(1, 11):
c += 1
i *= a
print(f’za {c}kg price: {i}’)
#python:
a = int(input(‘enter the price: ‘))
c = 0
for i in range(1, 11):
c += 1
i *= a
print(f'{c}kg price: {i}’)