Learning Perl: 2.12. Exercises

Previous Page
Next Page

 

2.12. Exercises

See Appendix A for answers to the following exercises:

  1. [5] Write a program that computes the circumference of a circle with a radius of 12.5. Circumference is 2p times the radius (approximately 2 times 3.141592654). The answer you get should be about 78.5.

  2. [4] Modify the program from the previous exercise to prompt for and accept a radius from the person running the program. So, if users enter 12.5 for the radius, they should get the same number as in the previous exercise.

  3. [4] Modify the program from the previous exercise so, if the user enters a number less than zero, the reported circumference will be zero, rather than negative.

  4. [8] Write a program that prompts for and reads two numbers (on separate lines of input) and prints out the product of the two numbers multiplied together.

  5. [8] Write a program that prompts for and reads a string and a number (on separate lines of input) and prints out the string the number of times indicated by the number on separate lines. (Hint: Use the "x" operator.) If the user enters "fred" and "3," the output should be three lines, each saying "fred". If the user enters "fred" and "299792," there may be a lot of output.

Previous Page
Next Page
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值