资源描述:
《13计师2班09号陈赞毅(实验2)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验23+程序设计初步实验报告班级:13计2班学号:09姓名:xxx指导教师xxx一、实验目的(1)掌握简单的C++程序的编写和调试方法。⑵掌握C卄程序中使用最多的语句一一if语句和whlie和输入输出的使用方法。二.实验内容输入一个小于1000的正数,要求输出他的平方根(如平方根不是整数,则输出其整数部分)。要求在输入数据后对其进行检查是否为小于1000的整数。若不是,则要求重新输入。编程如下:#include#includeintmain(){inti,r;printf(Hpleaseent
2、erthenumberbetween0to1000:n);scanf(H%dn,&i);if(i<=1000&&i>=0)r=sqrt(i);printf(H%d,r);}elseprintf(nerror,pleaseenteragainu);return0;}2•有人函数y=-l(x<0),y=0(x=0),y=l(x>0)o#includeintmain(){intx,y;printf(npleaseenter(x):n);scanf(H%dl&x);if(x<0)y=-i;elseif(x=
3、0)y=o;elsereturn0;3•给出成绩分数,要求输出成绩等级ABCDo90到10为A,80到89为B,70到79为C,60到69为D,60以下为E。#includeintmain(){inti;scanf(H%dH,&i);printf(Hyourscore:1*);charx;if(i>=90&&i<=100){x=*a*;}if(i>=80&&i<=89){}if(i>=70&&i<=79){x=,c,;}if(i<=60&&i>=69){x=,d,;}if(i<=60&&i>=0){switch
4、(x)case*a*:printf(,,%cH/A,);break;caseb:printf(u%cu;B,);break;case'd':printf(H%cM/D,);break;case'e':printf(n%cn/E*);break;default:printf(n错误,请重新输入:n);}return0;4•给一个不多于5位的正整数,要求:1.求出它是几位数。2.分别输出每一位数字。3.安逆序输出各位数字,如123,应输出321。#include#includei
5、ntmain(){intnumJndiv,ten,hundred,thousand,ten_thousand,place;printf(H请?输??入••?一。?个?整?数?y(e?§0到??99999)e?:eo");scanf(H%dM,&num);if(num>9999)place=5;elseif(num>999)place=4;elseif(num>99)place=3;elseif(num>9)place=2;elseplace=l;printf位?数?y:eo%dn,place);printf(”每?位?数?y
6、为a:eon);ten_thousand=num/10000;thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten_thousand*10000-thousandH:1000)/100;ten=(int)(num-ten_thousand^l0000-thousand*1000-hundred*100)/10indiv=(int)(num・ten_thoiisand*10000・thoiisaiid*1000・hiindred*100・ten*10);
7、printf(”每?一。?位?的??数?y字??为a:eoH);switch(place)printf(n反口??序••°数?y字??为a:%dn,indiv);break;case2:printf(H%d,%d,ten,indiv);printf(n反口??序••°数?y字??为a:%d,%d”,indiv,ten);break;case3:printf(K%d,%d,%dn,hundred,ten,indiv);printf(n反Q??序°数?y字??为a:%d,%d,%d'',indiv,ten,hu
8、ndred);break;case4:printf(''%d,%d,%d,%dn9thousand9hundred9ten9indiv);printf(n反口??序°数?y字??为a:%d,%d,%d,%dn,indiv,ten,hundred,thou