c语言习题及解答_爱课程mooc

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
输出样例:
#include<stdio.h>
int main()
{
printf("Input x:\n");
int x;
scanf("%d", &x);
if(x<=0)
{
x=-x;
}
int a, b, c, d;
a=x/1000;
b=x/100%10;
c=x/10%10;
d=x%10;
printf("y=%d\n", d*1000+c*100+b*10+a);
hello world!
#include <stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
1.2
在屏幕上输出多行信息(3分)
题目内容:
使用printf()函数在屏幕上输出以下多行信息:
hello world!
hello hit!
hello everyone!
第一章
1.1
题目内容:
使用printf()在屏幕上输出hello world!
提示:
#include <stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
输入格式:

输出格式:
输出提示信息:"hello world!\n"
输入样例:
输出样例:
输入样例:
输出样例:
#include<stdio.h>
int main()
1.2,3.4↙
result=13.00
输入格式:
"%f,%f"
输出格式:
输入提示信息:"please input x and y:\n"
输出格式:"result=%.2f\n"
输入样例:
输出样例:
#include<stdio.h>
#include<math.h>
int mห้องสมุดไป่ตู้in()
{
printf("please input x and y:\n");
return 0;
}
第三章
3.1
计算两个数的平方和(3分)
题目内容:
从键盘读入两个实数,编程计算并输出它们的平方和,要求使用数学函数pow(x,y)计算平方值,输出结果保留2位小数。
提示:使用数学函数需要在程序中加入编译预处理命令#include <math.h>
以下为程序的输出示例:
please input x and y:
float x, y;
scanf("%f,%f", &x, &y);
printf("result=%.2f\n", pow(x,2)+pow(y,2));
return 0;
}
3.2
逆序数的拆分计算(3分)
题目内容:
从键盘输入一个4位数的整数,编程计算并输出它的逆序数(忽略整数前的正负号)。例如,输入-1234,忽略负号,由1234分离出其千位1、百位2、十位3、个位4,然后计算4*1000+3*100+2*10+1 = 4321,并输出4321。再将得到的逆序数4321拆分为两个2位数的正整数43和21,计算并输出拆分后的两个数的平方和的结果。
以下为程序的输出示例:
input your English name:
tom↙
Tom
t:20
o:15
m:13
输入格式:
"%c%c%c"
输出格式:
输入提示信息:"input your English name:\n"
首字母大写的英文姓名的输出格式:"%c%c%c\n"
姓名中每个字母在26个英文字母中的序号的输出格式:"%c:%d\n"
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和 必须利用宏常量表示。
以下是程序的输出示例:
Input x:
-1234↙
y=4321
a=43,b=21
result=2290
输入格式:
"%d"
输出格式:
输入提示信息:"Input x:\n"
逆序数输出格式:"y=%d\n"
逆序数拆分后的输出格式:"a=%d,b=%d\n"
平方和的输出格式:"result=%d\n"
输入样例:
提示:
在printf()函数中转义字符‘\n’表示换行。
输入格式:
输出格式:
输出提示信息:
"hello world!\n"
"hello hit!\n"
"hello everyone!\n"
输入样例:
输出样例:
hello world!
hello hit!
hello everyone!
#include <stdio.h>
printf("a=%d,b=%d\n", d*10+c, b*10+a);
printf("result=%d\n", (b*10+a)*(b*10+a)+(d*10+c)*(d*10+c));
return 0;
}
3.3
拆分英文名(3分)
题目内容:
从键盘输入某同学的英文名(小写输入,假设学生的英文名只包含3个字母。如: tom),编写程序在屏幕上输出该同学的英文名,且首字母大写(如: Tom)。同时输出组成该英文名的所有英文字符在26个英文字母中的序号。
输入格式:

输出格式:
长方体的体积输出格式:"volume=%.3f\n"
输入样例:
输出样例:
#include<stdio.h>
int main()
{
const float l=1.2;
const float x=4.3;
const float y=6.4;
printf("volume=%.3f\n", l*x*y);
输入格式:

输出格式:
半圆的面积输出格式:"Area=%f\n"
半圆弧的周长输出格式:"circumference=%f\n"
输入样例:
输出样例:
Area=44.123632
circumference=16.650427
#include<stdio.h>
#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常量表示。
相关文档
最新文档