For6. Дано вещественное число — цена 1 кг конфет. Вывести стоимость 1.2, 1.4, …, 2 кг конфет.
Решение 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.2 to 2 kg of sweets print("Cost of sweets:") for kg in range(12, 21, 2): cost = kg * 0.1 * price_per_kg print(f"{kg * 0.1:.1f} kg: {cost:.2f}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 | program For6; var C:Real; i:Integer; begin Write('Введите стоимость 1 кг конфет: '); Readln(C); Writeln('Введите стоимость конфет: '); For i:=1 to 5 do Writeln((1+i*2/10),'??: ',(1+i*2/10)*C); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include int main(void) { float c; printf("Cost:"); scanf ("%f", &c); float m; for (m = 1.2; m<2.1; m+=0.1) printf("%f kg = %f \n ",m,c*m); return 0; } |
#include
using namespace std;
int main(){
float c;
cout <> c;
float m;
for (m = 1.2; m<2.1; m+=0.1)
cout << c*m<<endl;
return 0;
}
C ++
#include
using namespace std;
int main(){
float c;
cout <> c;
float m;
for (m = 1.2; m<2.1; m+=0.1)
cout << c*m<<endl;
return 0;
}
kotlin:
fun main(){
var kg = 5.25
for(i in 12..20 step 2){
var plus=i.toFloat()/10
println(«$i) $plus кг конфет = ${plus*kg}»)
}
}
разве m+=0.1 ? может быть 0.2 ? то есть m+=0.2
да
fun main() {
val A = 5
for(i in 12 .. 20 step 2){
print(«${i/10.toDouble()}kg = «); println((i/10.toDouble() * A).toString() + «rub»)
}
}
//Swift
var a: Double = 100
for i in 1…20{
print (Double(i)/10 * a )
}
А можно пожалуйста в JavaScript?
{
let price = 14.99
for (let i=1.2; i<2; i+=0.2){
console.log(i, price*i);
}
}
{
let price = 14.99
for (let i=1.2; i<2; i+=0.2){
console.log(i, price*i);
}
}
можно на for5,4,3 пж
Scanner sc = new Scanner(System.in);
float a = sc.nextFloat();
for (float i = 1.2f; i<2.1f; i+=0.2f){
System.out.println(i+"кг="+a*i);
}
cena=float(input())
kg=1.2
for k in range(0,5):
print(kg*cena,kg,cena)
kg+=0.2
python
#include
using namespace std;
int main()
{
float c, m;
cout <> c;
cout << "Stoimost konfet" << endl;
for (m = 1.2; m < 2.1; m += 0.1)
cout << m << " kg = " << c*m << endl;
return 0;
}
c++
#include
using namespace std;
int main()
{
float c, m;
cout <> c;
cout << "Stoimost konfet" << endl;
for (m = 1.2; m < 2.1; m += 0.1)
cout << m << " kg = " << c*m << endl;
return 0;
}
//C++
#include
using namespace std;
int main()
{
float n;
cout<>n;
for (float i=1; i<=2.2; i=i+0.2)
{
cout<< i << "kg = " << n*i << "$" << endl;
}
return 0;
}