高级语言程序设计课程第三次个人作业

这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/gjyycx/
这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/gjyycx/homework/13574
学号:102500420
姓名:连骁晗
一.编写并运行书本第4章4.8编程练习题目中的第2题第4题,第6题第8题。
4.8.2
4.8
4.8.3
4.8
4.8.4
4.8
4.8.6
4.8
4.8.7
4.8
4.8.8
4.8
二.编写并运行书本第5章5.11编程练习题目中的第1题~第9题。
5.11.1
5.11
5.11.2
5.11
5.11.3
5.11
5.11.4
5.11
5.11.5
5.11
5.11.6
5.11
5.11.7
5.11
5.11.8
5.11
5.11.9
5.11
三.运行以下程序给出程序结果(无需代码,截图程序输出结果,如有错误可自行修改)。
(1) #include<stdio.h>

include <string.h> // provides strlen() prototype

define PRAISE "What a super marvelous name!"

int main(void)
{
char name[40];
printf("What's your name?\n");
scanf("%s", name);
printf("Hello, %s. %s\n", name, PRAISE); printf("Your name of %d letters occupies %d memory cells.\n", strlen(name), sizeof name); printf("The phrase of praise has %d letters ", strlen(PRAISE));
printf("and occupies %d memory cells.\n", sizeof PRAISE); }
(2) #include<stdio.h>

define SQUARES 64 //棋盘上的方格数

define CROP 1E15 //以粒计的美国小麦产量

int main(void)
{
double current, total;
int count = 1;
printf("square grains total ");
printf("fraction of \n");
printf(" added grains ");
printf("US total\n");
total = current = 1.0; // start with one grain
printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);
while (count < SQUARES)
{
count = count + 1;
current = 2.0 * current;
total = total + current; // update total
printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP);
}
printf("That's all.\n"); }
(3) #include<stdio.h>
int main(void)
{
char ch; int i;
float fl;
fl = i = ch = 'C';
printf("ch = %c, i = %d, fl = %2.2f\n", ch, i, fl);
ch = ch + 1;
i = fl + 2 * ch;
fl = 2.0 * ch + i;
printf("ch = %c, i = %d, fl = %2.2f\n", ch, i, fl);
ch = 5212205.17;
printf("Now ch = %c\n", ch); return 0; }
(4) #include <stdio.h>
void pound(int n);
void main()
{
int times = 5;
char ch = '!';
float f = 6.0;
pound(times);
pound(ch);
pound((int) f);
}
void pound(int n)
{
while (n-- > 0)
printf("#");
printf("\n"); }
设计一个可以将程序运算符优先级展示出来的程序(例如自增或者自减运算与四则运算符混用)。
设计一个程序将这些运算符的优先级按照从高到低一行行展示出来。
1.
自编1
2.
自编2
3.
自编3
4.
自编4
5.
自编5
6.
自编6
总结:学会while语句

posted @ 2025-11-01 15:45  芸芸芸芸?  阅读(4)  评论(0)    收藏  举报