For5. Дано вещественное число — цена 1 кг конфет. Вывести стоимость 0.1, 0.2, …, 1 кг конфет.
Решение 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 0.1 to 1 kg of sweets print("Cost of sweets:") for kg in range(1, 11): cost = kg * 0.1 * price_per_kg print(f"{0.1 * kg:.1f} kg: {cost:.2f}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 | program For5; var C:Real; i:Integer; begin Write('Введите стоимость 1 кг конфет: '); Readln(C); Writeln('Cтоимость конфет: '); For i:=1 to 10 do Writeln(i/10,'кг: ',i/10*C); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 | #include int main(void) { float c; printf("Cost:"); scanf ("%f", &c); float m; for (m = 0.1; m<1.1; m+=0.1) printf("%f kg = %f \n ",m,c*m); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <iostream> using namespace std; int main() { float c, m; cout << "Vvedite stoimost 1 kg konfet:"; cin >> c; cout << "Stoimost konfet" << endl; for (m = 0.1; m < 1.1; m += 0.1) cout << m << " kg = " << c*m << endl; return 0; } |
как решить на с++
Добрый день, Ибрагим. Решение на С++ добавлено.
Здравствуйте !
Можете ли вы добавить решение на C# ?
На WinFormApp:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ZadachaAbramyan
{
public partial class For5 : Form
{
public For5()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Ffor f = new Ffor();
f.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
for (double i = 0.1; i < 1; i += 0.1)
{
listBox1.Items.Add(i * a);
}
}
}
}
если сам понимаешь с# то легко решить задачи посмотрев на решение
здравствуйте можна на пайтоне
нельзя
Здраствуйте можете отправить ответы на Java ?
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.Write(«Price=»);
double c = Convert.ToDouble(Console.ReadLine());
double i;
for (i = 0.1; i < 1; i += 0.1)
Console.WriteLine($"{i} kg = {c * i}");
Console.ReadKey();
}
}
}
добрый вечер, а как решить в С++ через do while?
fun main() {
val A = 5
for(i in 1 .. 10){
print(«${i/10.toDouble()}kg = «); println((i/10.toDouble() * A).toString() + «rub»)
}
}
//SWIFT
var a: Double = 85
for i in 1…10{
print(Double(i)/10 * a)
}
1 c
Scanner sc = new Scanner(System.in);
float n = sc.nextFloat();
for (float i = 0.1f; i<1.1f; i+=0.1f){
System.out.println(i+"кг="+n*i);
}
C#
Console.WriteLine(«Введите цену конфет: «);
double price = Convert.ToDouble(Console.ReadLine());
for (double i = 0.1; i <= 1 ; i+=0.1)
{
Console.WriteLine($"Цена за {Math.Round(i, 1)} кг конфет равна {Math.Round(i * price, 2)}");
}
можно на JavaScript пж
Java
Scanner scanner = new Scanner(System.in);
System.out.println(«Цена конфет:»);
double price = scanner.nextDouble();
double i;
for ( i = 1; i < 10; i++) {
System.out.println(i/10 + " kg= " + i * price);
#python:
a = int(input(‘enter the price: ‘))
c = 0
for i in range(1, 11):
c += 0.1
i = c*a
print(f’kg: {c} price: {i}$’)