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

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

这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/2026gjyycxsj/homework/16750

学号:102500314

姓名:杨成
运行以下程序给出程序结果(无需代码,截图程序输出结果,如有错误可自行修改)。
(1) #include<stdio.h>

int main(void) // 对用户输入的整数求和

{ long num; long sum = 0L; int status;

printf("Please enter an integer to be summed ");

printf("(q to quit): ");

status = scanf("%ld", &num);

while (status == 1) // == means "is equal to"

{ sum = sum + num;

printf("Please enter next integer (q to quit): ");

status = scanf("%ld", &num);

}

printf("Those integers sum to %ld.\n", sum);

return 0;

}
(2) #include <math.h>

include <stdio.h>

int main(void)

{ const double ANSWER = 3.14159;

double response;

printf("What is the value of pi?\n");

scanf("%lf", &response);

while (fabs(response - ANSWER) > 0.0001)

{ printf("Try again!\n");

scanf("%lf", &response);

}

printf("Close enough!\n");

return 0;

}
1

2
用while和do while分别设计程序实现:用公式π/4=1-1/3+1/5-1/7+1/9+...求π的近似值,直到某一项的绝对值小于10-4为止,对两个程序的不同之处进行讨论。
3

4
不同在于do while至少执行一次
设计一个程序,实现功能:逻辑表达式中的运算符,只有会影响表达式求值时,才会执行。
5
用for循环输出六行,第一行有FEDCBA,第二行是FEDCB,第三行是FEDC....,以此类推。
6
编程输入n, 计算s=1+(1+2)+(1+2+3)+…+(1+2+3+4+…n)。
7
用for循环给一组整型类型的数组进行赋值,输出,以及求和,数组长度为8
8
设计一个if和else的多分支程序(分支数目大于3),该多分支程序再用switch语句进行改写,同时设计一个使用条件运算符(?:)的双分支语句
9

9

9
设计一个循环程序,再循环中用break和continue语句,实现不同的程序效果,给出结果并讨论
10
设计一个程序求100~200间的全部素数,给出算法思想、传统流程图、程序NS流程图
11
编写并运行书本第6章6.16编程练习题目中的第1,5,7,10,13,16,18题。
6.16.1
6.16
6.16.5
5
6.16.7
6.16
6.16.10
6.16
6.16.13
6.16
6.16.16
6.16
6.16.18
6.16
编写并运行书本第7章7.12编程练习题目中的第1,2,4~5,7题。
7.1
7.12
7.2
7.12
7.4
7.12
7.5
7.12
7.7
7.12

总结与思考:掌握while 和do while循环体以及条件判断语句等

posted @ 2026-11-09 13:58  yangcheng123  阅读(8)  评论(0)    收藏  举报