北邮第五章实验.docVIP

  • 26
  • 0
  • 约5.03千字
  • 约 7页
  • 2018-11-19 发布于广东
  • 举报
北邮第五章实验.doc

第五章 1、编写完成下列任务的程序段。 计算整数a除以整数b的商的整数部分。 计算整数a除以整数b的余数。 用(a)和(b)中的程序段编写一个程序,输入1到32 767之间的整数,打印成 一系列数字,毎一对数字之I川用两个空格分开。例如,整数4 562打印为: 4 5 6 2 #include 〈iostream〉 using namespace std; iniineint integer(inta, int b) { return a/b; } inlineint residue(inta, int b) { returna%b: } void main() { const short idiv[4]={10000,1000,100,10}: short number: shortres, intg; coutz,input number (1 ?32767, 0 for end.):; cin?number; while (number !=0) { for (int k=0; k〈4;k++) { intg=integer(number, idiv[k:); res二residue(number, idiv[k]); if (intg10 intg0) { coutintg,z ” ?、 number=res; } } cout〈rcs〈 cndl; cout〈〈〃inpu

文档评论(0)

1亿VIP精品文档

相关文档