C++与数据结构基础简明教程课后习题答案 下载本文

{

cout<<\ goto onerror; }

cout<<\id is\

cout<<\score is\ } return 0; } 2-5

//判断输入字符类别 #include using namespace std; int main() { char zifu; int ascii;

cout<<\input a characteristic\\n\cin>>zifu; ascii=zifu;

if (ascii>=48&&ascii<=57) {

cout<<\数字\\n\ goto end; }

if (ascii>=97&&ascii<=122) {

cout<<\小写字母\\n\

goto end; }

if (ascii>=65&&ascii<=90) {

cout<<\大写字母\\n\ goto end; }

cout<<\其他字符\cout<

//求圆周率的近似值 #include #include using namespace std; int main() {

int xishu=-1; double danshu=1.0; int i=1;

double sifenzhipi=0; do {

xishu=xishu*(-1); danshu=1.0/(2*i-1);

sifenzhipi=sifenzhipi+xishu*danshu;

i++; }

while(danshu>=0.000001);

cout<

//输出斐波那契数列前40个数,以8*5的格式输出 #include #include using namespace std; int main() {

int b=2; int feibo1=0; int feibo2=1;

cout<

int a=feibo2; feibo2=feibo1+feibo2; feibo1=a;

cout<

if(b%8==0) cout<

return 0; } 2-8

//统计输入的元音字母个数 #include using namespace std; int main() {

char zimu; int a,e,i,o,u; a=e=u=i=o=0; begin:cin>>zimu; switch(zimu) {

case 'a' :a++;break; case 'e' :e++;break; case 'i' :i++;break; case 'o' :o++;break; case 'u' :u++;break; case '#' :goto end; }

goto begin;

end:cout<

//计算5!+6!+7! #include