小编pra*_*ani的帖子

在线上打印数组的内容

我是ruby的新手,正在尝试使用arrays.i想要以单行打印数组.这是代码块(请忽略任何错误)

array=[]

puts "Choose an option: ","1.Push, 2.Pop, 3.Display Length"
choice=gets.to_i
while choice!=4
if choice==1
    puts "enter Number of elements to be pushed"
    n=gets.to_i
    n.times do
      puts "Enter element"
    el=gets.to_s
    array.push el
    end
  puts array
elsif choice==2
    puts array.pop

elsif choice==3
    puts array.length

else
  puts "invalid"
end
end
Run Code Online (Sandbox Code Playgroud)

当我打印我的阵列时,if choice==1我得到不同线路上的所有输出,例如

hello
i
am
beginner
to
ruby
Run Code Online (Sandbox Code Playgroud)

无论如何将输出放在一行?即hello i am beginner to ruby

编辑:我甚至尝试过使用puts array.join(' '),但这也不起作用.

ruby arrays

3
推荐指数
1
解决办法
1万
查看次数

添加不在c中工作

我正在尝试添加c代码,但我的程序没有执行,不幸的是,代码块关闭了.错误是什么?

void main()
{
    float  a,b;

    printf("%30sAddition Of Numbers\n");
    printf("\nEnter Number 1: ");
    scanf("%f",&a);
    printf("\nEnter Number 2: ");
    scanf("%f",&b);

    printf("\nThe addition of %0.3f and %0.3f is %0.3f",a,b,(a+b));

}
Run Code Online (Sandbox Code Playgroud)

我想直接在printf语句中使用float输入添加结果,但我没有让它工作.

我也尝试将结果放在变量a中,但它也没有用.

    void main()
{
    float  a,b;

    printf("%30sAddition Of Numbers\n");
    printf("\nEnter Number 1: ");
    scanf("%f",&a);
    printf("\nEnter Number 2: ");
    scanf("%f",&b);
    a=a+b;
    printf("\nThe addition of %0.3f and %0.3f is %0.3f",a,b,a);

}
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

c printf addition format-specifiers

0
推荐指数
1
解决办法
300
查看次数

标签 统计

addition ×1

arrays ×1

c ×1

format-specifiers ×1

printf ×1

ruby ×1