爱课程第四周c语言测试答案,c语言习题含答案 爱课程mooc.pdf

本文涵盖C++编程基础知识,包括printf函数的使用、多行信息输出、半圆弧周长与面积计算、长方体体积计算,以及数学函数和数据结构的实战应用。通过实例展示如何利用printf和数学库进行精确计算,并涉及了常量定义与控制台输出。
摘要由CSDN通过智能技术生成

第一章

1.1

题目内容:

使用 printf()在屏幕上输出 hello world!

提示:

#include

int main()

{

printf("hello world!\n");

return 0;

}

输入格式:

输出格式:

输出提示信息:"hello world!\n"

输入样例:

输出样例:

hello world!

#include

int main()

{

printf("hello world!\n");

return 0;

}

1.2

在屏幕上输出多行信息(3 分)

题目内容:

使用 printf()函数在屏幕上输出以下多行信息:

hello world!

hello hit!

hello everyone!

提示:

在 printf()函数中转义字符‘\n’表示换行。

输入格式:

输出格式:

输出提示信息:

"hello world!\n"

"hello hit!\n"

"hello everyone!\n"

输入样例:

输出样例:

hello world!

hello hit!

hello everyone!

#include

int main()

{

printf("hello world!\n");

printf("hello hit!\n");

printf("hello everyone!\n");

return 0;

}

1.3

计算半圆弧的周长及半圆面积(3 分)

题目内容:

编程并输出半径 r=5.3 的半圆弧的周长及该半圆的面积, 的取值为 3.14159 。要求半径 r 和 必须利用宏常量表示。

输入格式:

输出格式:

半圆的面积输出格式: "Area=%f\n"

半圆弧的周长输出格式: "circumference=%f\n"

输入样例:

输出样例:

Area=44.123632

circumference=16.650427

#include

#define PI 3.14159

#define R 5.3

int main()

{

printf("Area=%f\n", R*R*PI/2);

printf("circumference=%f\n", 2*R*PI/2);

return 0;

}

1.4

计算长方体体积(3 分)

题目内容:

编程并输出长 1.2、宽4.3 、高 6.4 的长方体的体积。要求长方体的长、宽、高必须利用 const 常量表示。

输入格式:

输出格式:

长方体的体积输出格式:"volume=%.3f\n"

输入样例:

输出样例:

#include

int main()

{

const float l=1.2;

const float x=4.3;

const float y=6.4;

printf("volume=%.3f\n", l*x*y);

return 0;

}

第三章

3.1

计算两个数的平方和(3 分)

题目内容:

从键盘读入两个实数,编程计算并输出它们的平方和,要求使用数学函数 pow(x,y)计算平方值,输出结果保留 2 位小数。

提示:使用数学函数需要在程序中加入编译预处理命令 #include

以下为程序的输出示例:

please input x and y:

1.2,3.4↙

result=13.00

输入格式:

"%f,%f"

输出格式:

输入提示信息:"please input x and y:\n"

输出格式:"result=%.2f\n"

输入样例:

输出样例:

#include

#include

int main()

{

printf("please input x and y:\n");

float x, y;

scanf("%f,%f", &x, &y);

printf("result=%.2f\n", pow(x,2)+pow(y,2));

return 0;

}

3.2

逆序数的拆分计算(3 分)

题目内容:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值