当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C语言程序设计》课程教学资源:实验三参考答案

资源类别:文库,文档格式:DOC,文档页数:5,文件大小:36.5KB,团购合买
点击下载完整版文档(DOC)

1.编写程序,输入一个字符ch,输出字符的类型,即字母( alpha)、数字( numerIc) 或其他字符( other)。 #indludestdio, h maino char ch ch=getchar; if(dh>=6588ch=978&dh=4888h10) 编写一个程序,用 scanf函数输入x的值,输出y值。注意表达式的书写方法 运行程序,输入ⅹ的值(分别用上述4种情况),检査输出的y值是否正确

1. 编写程序,输入一个字符 ch,输出字符的类型,即字母(alpha)、数字(numeric) 或其他字符(other)。 #include “stdio.h” main() { char ch; ch=getchar(); if(ch>=65&&ch=97&&ch=48&&ch0):”); scanf(“%d”,&m); printf(“\nThe integer is %d”,m); if(m%2==0) printf(“\nThis is a even!”); else printf(“\nThis is a odd!”); } 3. 有一函数:        + − − + − + − = 5 3log (2 1) 13 3 5 1 1 2 10 2 3 x x x x x y ( ) ( ) ( ) ( 10) 1 10 1 1 1    −    − x x x x 编写一个程序,用 scanf 函数输入 x 的值,输出 y 值。注意表达式的书写方法。 运行程序,输入 x 的值(分别用上述 4 种情况),检查输出的 y 值是否正确

#indude"math h ain float X,y; printf \nPlease input the x: ) scanf( %f,&x) y=pow(x, 3)-1 else +1 if(Xc&&b+c>a&&a+c>b) if(a==b&&b==c) printf \nThis is an equilateral triangle if(a==blb==clla==c)

#include “math.h” main() { float x,y; printf(“\nPlease input the x:”); scanf(“%f”,&x); if(xc&&b+c>a&&a+c>b) { if(a==b&&b==c) printf(“\nThis is an equilateral triangle!”); else if(a==b||b==c||a==c)

printf nThis is an isosceles triangle else printf nThis is an unequilateral triangle!") else printf \ nThis is not a triangle 7.简单选择界面的编程。从键盘输入整数,输出不同的字符串: 输入1,输出 Good morning ●输入2,输出 Good afternoon; 输入3,输出 Good evening 输入4,输出 Good night; 输入其他数字,输出 Byebye maino int n: printf( " \nPlease input a number scanf("%d", &n) switch(n) case 1: printf( " Good morning ) break; case 2: printf(" Good afternoon ) break; case 3: printf(" Good evening"); break; case 4: printf("Good night ) break default: printf(" Byebye) 8.已知从银行贷款月利率为:期限一年,为0.90%;期限2年,为1%;期限3年,为1.11% 三年以上为1.2%。从键盘输入贷款金额和期限,计算到期后应归还银行本金和利息合计为 多少钱。 #indude ma float base rate sum descr: printf( \ eNter the base and the year scanf(%f%d", &base, &year) switch(year) case 1: rate=0. 009: break. case 2: rate=0.01: break

printf(“\nThis is an isosceles triangle!”); else printf(“\nThis is an unequilateral triangle!”); } else printf(“\nThis is not a triangle!”); } 7. 简单选择界面的编程。从键盘输入整数,输出不同的字符串: ⚫ 输入 1,输出 Good morning; ⚫ 输入 2,输出 Good afternoon; ⚫ 输入 3,输出 Good evening; ⚫ 输入 4,输出 Good night; ⚫ 输入其他数字,输出 Bye bye。 main() { int n; printf("\nPlease input a number:"); scanf("%d",&n); switch(n) { case 1:printf("Good morning");break; case 2:printf("Good afternoon");break; case 3:printf("Good evening");break; case 4:printf("Good night");break; default:printf("Bye bye"); } } 8.已知从银行贷款月利率为:期限一年,为 0.90%;期限 2 年,为 1%;期限 3 年,为 1.11%; 三年以上为 1.2%。从键盘输入贷款金额和期限,计算到期后应归还银行本金和利息合计为 多少钱。 #include main() { int year; float base,rate,sum; clrscr(); printf("\nEnter the base and the year:"); scanf("%f%d",&base,&year); switch(year) { case 1: rate=0.009;break; case 2: rate=0.01;break;

case 3: rate=0.0111: break. default rate=0.012 sum=base* pow(1+rate, 12 year) printf("sum is %.2f n",sum) 9.输入一个不多于5位的正整数,要求:①求出它是几位数;②分别打印出 每一位数字;③按逆序打印出各位数字。 要准备以下测试数据: 1位正整数 2位正整数 3位正整数 4位正整数 5位正整数 除此之外,程序还应当对不合法的输入作必要的处理,如负数或超过5位的正整 mal long m; int a, b, c, d, e: printf( \nplease input a integer (m>0&&m=100008&m=10008&m<=9999) printf( \ nThis is a 4 integer!) a=m/1000 b=m/100-a*10 m/10-a*100-b*10; d=m%1000 printf \nThe integer is %d %d %d %d! a, b, c, d); printf \nThe inverse is %d %d %d %d! d, c b, a);

case 3: rate=0.0111;break; default: rate=0.012; } sum=base*pow(1+rate,12*year); printf("sum is %.2f\n",sum); } 9. 输入一个不多于 5 位的正整数,要求:① 求出它是几位数;② 分别打印出 每一位数字;③ 按逆序打印出各位数字。 要准备以下测试数据:  1 位正整数  2 位正整数  3 位正整数  4 位正整数  5 位正整数 除此之外,程序还应当对不合法的输入作必要的处理,如负数或超过 5 位的正整 数。 main() { long m; int a,b,c,d,e; printf(“\nPlease input a integer(m>0&&m=10000&&m=1000&&m<=9999) { printf(“\nThis is a 4 integer!”); a=m/1000; b=m/100-a*10; c=m/10-a*100-b*10; d=m%1000; printf(“\nThe integer is %d %d %d %d!”,a,b,c,d); printf(“\nThe inverse is %d %d %d %d!”,d,c,b,a);

else ifm>=10088m=1088m=1&&m<=9) printf \ nThis is a 1 integer! ) printf( nThe integer is %ld ,m) else printf \nNot the effect integer! ")

} else if(m>=100&&m=10&&m=1&&m<=9) { printf(“\nThis is a 1 integer!”); printf(“\nThe integer is %ld”,m); } else printf(“\nNot the effect integer!”); }

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有