高级语言程序设计第二次作业

这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/2024C/

这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/2024C/homework/13282

学号:092300125

姓名:张天荣

3.11 编程练习

1

通过试验观察系统如何处理整数上溢、浮点数上溢和浮点数下溢的情况

#include<stdio.h>
#include<limits.h>
#include<float.h> 

int main(void) {

    printf("%d %d\n", INT_MAX, INT_MAX + 1);
    printf("%e %e %e %e\n", DBL_MAX, DBL_MAX + 1.0, DBL_MIN, DBL_MIN - 1.0);

    return 0;

}

2

编写一个程序,要求提示输入一个ASCII码值,如何打印输入的字符

#include<stdio.h>
int main(void){   

    int a;
    printf("Enter a value of char int ASCII:\n");
    scanf("%d",&a);
    printf("You input value is %d ,and char is %c .\n", a,a);

    return 0;

}

3

编写一个程序,发出一声警报,然后打印下面的文本:
Startled by the sudden sudden sound, Sally shouted,
"By the Great Pumpkin, what was that!"

#include<stdio.h>
int main(void){

    char ch='\a';
    printf("%c",ch);
    printf("Started by the sudden sound, Sally shouted, \n");
    printf("\"BY the Great Pumpkin , what was that !\"\n");

    return 0;

}

4

编写一个程序,读取一个浮点数,先打印成小数点形式,再打印成指数形式。然后,如果系统支持,再打印成p计数法(即十六进制计数法)。按以下格式输出(实际显示的指数位数因系统而异):
Enter a floating-point value: 64.25
fixed-point notation: 64.250000
exponential notation: 6.425000e+01
p notation: 0x1.01p+6

#include<stdio.h>
int main(void){  

    float a;
    printf("\"Enter a floating-point value:\"\n");
    scanf("%f",&a);
    printf("fixed-point notation: %f \n",a);
    printf("exponential notation; %e \n",a);
    printf("p notation: %a",a);

    return 0;

}

5

一年大约有3.15610^7秒。编写一个程序,提示用户输入年龄,然后显示该年龄对应的秒数

#include<stdio.h>
int main(void){

    int age;    
    float second;
    printf("请输入年龄: \n");
    scanf("%d",&age);
    second=3.156e7*age;
    printf("对应的秒数为: %f",second);

    return 0;

}

6

1个水分子的质量约为3.0*10^-23克。一夸脱水大约是950克。编写一个程序,提示用户输入水的夸脱数,并显示水分子的数量

#include<stdio.h>
int main(void){

	double a;
	printf("请输入水的夸脱数:");
	scanf("%lf", &a);
	printf("水分子的数量为:%e",a*950.0/3.0e-23);

    return 0;

}

7

1英寸相当于2.54厘米。编写一个程序,提示用户输入身高(/英寸),然后以厘米为单位显示身高

#pragma warning(disable:4996)
#include<stdio.h>
int main(void){

	double a;
	printf("请输入身高:");
	scanf("%lf", &a);
	printf("%.2lf",a*2.54);

    return 0;

}

8

在美国的体积测量系统中,1品脱等于2杯,1杯等于8盎司,1盎司等于2大汤勺,1大汤勺等于3茶勺。编写一个程序,提示用户输入杯数,并以品脱、盎司、汤勺、茶勺为单位显示等价容量。思考对于该程序,为何使用浮点类型比整数类型更合适?

#pragma warning(disable:4996)
#include<stdio.h>
int main(void){

	double a;
	printf("请输入杯数:");
	scanf("%lf", &a);
	printf("品脱:%.2lf 盎司:%.2lf 汤勺:%.2lf 茶勺:%.2lf",a/2.0,a*8.0,a*16.0,a*48.0);

    return 0;

}

程序清单

3.1

3.2

3.3

3.4

3.5

3.6

3.7

3.8

3.9

3.10

posted @ 2024-10-03 00:47  hfdc  阅读(7)  评论(0编辑  收藏  举报