1 / 6

上机实验 2 : 简单程序设计

上机实验 2 : 简单程序设计. 1. 【 2.2.6】 【 2.2. 三⑷ 】 ( filename:cp21.c ) 《 求两个整数的和、差、积、商与余数 》 输入两个整数 num1 和 num2 , 计算并输出它们的和、 差、积、商 ( 用实数表示 , 保留 2 位小数点 ) 与余数 。 【 输入输出样例 】 Enter num1: 5 Enter num2: 3 5+3=8 5-3=2 5*3=15 5/3=1.67 5%3=2.

Download Presentation

上机实验 2 : 简单程序设计

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 上机实验 2:简单程序设计 1.【2.2.6】【2.2.三⑷】 (filename:cp21.c) 《求两个整数的和、差、积、商与余数》 输入两个整数 num1 和 num2,计算并输出它们的和、 差、积、商(用实数表示,保留2位小数点)与余数。 【输入输出样例】 Enter num1:5 Enter num2:3 5+3=8 5-3=2 5*3=15 5/3=1.67 5%3=2

  2. 2. 【2.2.7】【2.2.三⑸】 (filename: cp22.c) 《计算旅途时间》 输入2个整数time1和time2,表示火车的出发时间 和到达时间,计算并输出旅途时间。有效的时间范围是 0000 ~2359(前两位表示小时,后两位表示分钟),不 需要考虑出发时间晚于到达时间的情况。 【输入输出样例】(括号内为说明文字) Enter time1:712(出发时间是7:12) Enter time2:1411(到达时间是14:11) The train journey time is 6 hours 59 minutes

  3. 3.【2.2.8】【2.2.三⑹】 (filename: cp23.c ) 《加密一个四位正整数》 输入一个四位正整数,将其加密后输出。方法是将 该数每一位上的数字加9,然后除以10 取余,作为该位 上的新数字,最后将千位和十位上的数字互换,百位和 个位上的数字互换,组成加密后的新四位数。 【输入输出样例】 (括号内为说明文字) Enter a number:1257 The encrypted number is 4601(每一位上的数字 加9除以10取余后得0146,交换后得到4601)

  4. 4.【2.3.5】【2.3.三⑷】 (filename:cp24.c) 《求1-1/4+1/7-1/10+1/13-1/16+…的前n 项之和》 输入一个正整数n,计算1-1/4+1/7-1/10+1/13-1/16+… 的前n 项之和,输出时保留3位小数。 【输入输出样例1】(下划线部分表示输入) Enter n: 3 sum=0.893 【输入输出样例2】(下划线部分表示输入) Enter n: 10 sum=0.819

  5. 5.【2.4.3】【2.4.三⑶】 (filename:cp25.c ) 《求组合数》 根据下列公式可以计算出从n 个不同元素中取出m 个元素(m≤n)的组合数。编写程序,输入2 个正整数m 和n(m≤n),计算并输出组合数。要求定义和调用函数 fact(n)计算n!,函数类型为double。 【输入输出样例】 Enter m:5 Enter n: 12 result=792

  6. 结 束

More Related