C语言程序设计(第3版)习题解答.docxVIP

  • 86
  • 0
  • 约2.37万字
  • 约 31页
  • 2023-07-11 发布于澳门
  • 举报
习 题 二 参 考 答 案 (1)编一程序,交换两个字符变量的值并输出。 void main() { char ch1=A,ch2=B,chTemp; printf(ch1=%c,ch2=%c\n,ch1,ch2); chTemp=ch1; ch1=ch2; ch2=chTemp;; printf(ch1=%c,ch2=%c\n,ch1,ch2); getch(); } (2)编一程序,从键盘输入一个实数,输出其绝对值。 void main() { float fx; printf(please input a float:); scanf(%f,fx); if(fx0) fx=-fx; printf(|fx|=%f,fx); getch(); } (3)编一程序,从键盘输入圆的半径,计算并输出圆的正内接六边形的面积,以及这个正六边形面积占圆面积之百分比。圆的正内接六边形的面积计算公式为:area=sqrt(3)*3/2r2。其中,r是圆半径,sqrt(3)是求3的平方根,∏是圆周率,area是圆正内接六边形的面积。 #include math.h #define PI 3.1415926 void main() { float fr,fArea,fSix

文档评论(0)

1亿VIP精品文档

相关文档