没有合适的资源?快使用搜索试试~ 我知道了~
首页C语言基础入门与实践:从屏幕输出到函数编程
C语言基础入门与实践:从屏幕输出到函数编程
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 39 浏览量
更新于2024-06-25
收藏 3.12MB PDF 举报
本资源是一份名为"C语言上机练习.pdf"的文档,它包含了C语言的基础入门教程和实践操作。该文档详细介绍了C语言的各个方面,包括基本语法、控制结构、输入输出以及函数的使用。 在第1章C语言概述中,文档首先引导读者编写简单的程序来熟悉C语言环境。通过实践,学习者可以学会如何使用`printf`函数在屏幕上输出文本和特定格式的字符串。例如,程序1演示了如何打印出欢迎语句和版权声明,而程序2则展示了如何利用循环结构和格式化输出创建星号图案。 接下来,文档关注到基本数学运算在C中的应用,如第11和12节的圆面积计算。通过定义符号常量`PI`并赋予其值3.14,学习者能够计算给定半径(例如5)的圆面积,并精确地输出结果。 更进一步,章节13和14涉及函数的使用,具体是自定义函数`add()`和`sub()`的编写。这些函数分别用于将两个整数(如20和10)相加和相减,然后通过`printf`函数展示计算结果,如"20+10=30"和"20-10=10"的形式。 整个文档旨在通过一系列上机练习,帮助读者逐步掌握C语言的基本概念和编程技巧,培养实际编程的能力,为后续深入学习和开发打下坚实的基础。无论是初学者还是有一定基础的C语言爱好者,这份文档都是进行实战操作和理论巩固的良好资源。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/87845209/bg10.jpg)
main()
{ float x, y, z,t;
printf("Please input 3 real numbers: ");
scanf("%f%f%f", &x, &y, &z);
if (x>y)
{ t=x; x=y; y=t; }
if (x>z)
{ t=x; x=z; z=t; }
if (y>z)
{ t=y; y=z; z=t; } /*此程序与上面的程序有何不同?*/
printf("%.3f, %.3f, %.3f\n", x, y, z);
} /*程序结束时,x, y, z 的值是否发生了变化?*/
Output
Please input 3 real numbers: 7.8 5 10
10.000, 7.800, 5.000
5-13 输入五级制成绩( A~E),输出相应的百分制成绩( 0~100)区间。五级制
/* Blue is input */
成绩对应百分制程序区间为:A(90~100)、B(80~89)、C(70~79)、D(60~69)
和 E(0~59)。例如:输入 B,输出(80~89)。
5-14 (1)用 switch 语句实现;(2)用 if 语句实现。
Program (1)
#include <stdio.h>
main()
{ char grade;
printf("Please input the grade: ");
scanf("%c", &grade);
switch (grade)
{ case 'A': printf("90~100\n"); break;
case 'B': printf("80~89\n"); break;
case 'C': printf("70~79\n"); break;
case 'D': printf("60~69\n"); break;
case 'E': printf("0~59\n"); break;
default: printf("Wrong grade! \n");
![](https://csdnimg.cn/release/download_crawler_static/87845209/bg11.jpg)
}
}
Program (2)
#include <stdio.h>
main()
{ char grade;
printf("Please input the grade: ");
scanf("%c", &grade);
if (grade=='A')
printf("90~100\n");
else if (grade=='B')
printf("80~89\n");
else if (grade=='C')
printf("70~79\n");
else if (grade=='D')
printf("60~69\n");
else if (grade=='E')
printf("0~59\n");
else
printf("Wrong grade! \n");
}
Output
Please input the grade: B
80~89
5-15 用 switch 语 句实 现 ,输入 数字 1~7 , 输 出对应 的英 文单 词 Monday,
/* Blue is input */
Tuesday, …, Sunday。
Program
#include <stdio.h>
main()
{ int day;
printf("Please input the day in a week: ");
scanf("%d", &day);
switch(day)
{ case 1: printf("Monday\n"); break;
![](https://csdnimg.cn/release/download_crawler_static/87845209/bg12.jpg)
}
}
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
default:
printf("Tuesday\n"); break;
printf("Wednesday\n"); break;
printf("Thursday\n"); break;
printf("Friday\n"); break;
printf("Saturday\n"); break;
printf("Sunday\n"); break;
printf("Wrong day! \n");
Output
Please input the day in a week: 4
Thursday
/* Blue is input */
5-16
5-17
5-18
5-19
5-20
5-21
某高校的某专业录取研究生的条件如下:
(1)英语成绩55
(2)政治成绩60
(3)专业课成绩60
(4)以上三科的总数学成绩200,或英语和专业课的总成绩130。
编写程序,读入一个学生的成绩(英语、政治和专业课),判断是否可以被
录取。
Program
#include <stdio.h>
main()
{ float english, politics, professional;
printf("Please input score of English: ");
scanf("%f", &english);
printf("Please input score of Politics: ");
scanf("%f", &politics);
printf("Please input score of the professional course: ");
scanf("%f", &professional);
if(english>=55 && politics>=60 && professional>=60 &&
(english+politics+professional>=200 ||
english+professional>=130))
printf("Congratulations! You have been admitted! \n");
else
printf("Sorry, you have been rejected! \n");
![](https://csdnimg.cn/release/download_crawler_static/87845209/bg13.jpg)
}
Output
Please input score of English: 60
Please input score of Politics: 70
Please input score of professional course: 60
Sorry, you have been rejected!
5-22
5-23
5-24
5-25
5-26
5-27
5-28
5-29
5-30
编写程序,计算下面二元方程的实数根。
ax
2
bx c 0
/* Blue is input */
/* Blue is input */
/* Blue is input */
应用如下规则:
(1)如果 a 和 b 的值为零,则没有解;
(2)如果 a 的值为零,则只有一个解(x=-c/b);
(3)如果 b
2
-4ac 为负数,则没有实数根;
(4)否则,有两个实数根:
b b
2
4ac
x
1
2a
b b
2
4ac
x
2
2a
输入 a, b 和 c 的值,输出求根的情况,如有实数根,则输出实数根的值。
Program
#include <stdio.h>
#include <math.h>
main ( )
{ float a, b, c, f;
printf ( "Please input the value of a, b and c in the quadratic
equation:\nax*x + bx + c = 0\n" );
printf ( "a = " ); scanf ( "%f", &a );
printf ( "b = " ); scanf ( "%f", &b );
printf ( "c = " ); scanf ( "%f", &c );
printf ( "About %.2fx*x + %.2fx + %.2f = 0: ", a, b, c );
if ( a == 0 && b == 0 )
printf("There is no solution!\n");
else if ( a == 0 )
printf("There is only one root: %.2f.\n",- c/b);
else
{ f = b * b - 4 * a * c;
if ( f <0 )
printf("There are no real root!\n");
else
![](https://csdnimg.cn/release/download_crawler_static/87845209/bg14.jpg)
}
}
printf("There are 2 real roots: %.2f, %.2f.\n",
(-b + sqrt(f))/2/a, (-b - sqrt(f))/2/a );
Output
Please input the value of a, b and c in the quadratic equation:
ax*x + bx + c = 0
a = -3 /* Blue is input */
b = 4 /* Blue is input */
c = 5 /* Blue is input */
About -3.00x*x + 4.00x+5.00 = 0: There are 2 real roots: -0.79, 2.12.
5-31
5-32
5-33
5-34
5-35
5-36
5-37
编写程序,读取 x 的值,求下面函数的值
1 for x 0
y
0 for x 0
1 for x 0
(1)用 else if 语句实现
(2)用嵌套 if 语句实现
(3)用条件运算符 ? : 实现
Program (1)
#include <stdio.h>
main ( )
{ float x;
printf ( "Please input the value of x: " );
scanf ( "%f", &x );
if ( x > 0 )
printf ( "y = 1\n" );
else if ( x == 0 )
printf ( "y = 0\n" );
else printf ( "y = -1\n" );
}
Program (2)
#include <stdio.h>
main ( )
{ float x;
剩余119页未读,继续阅读
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
hhappy0123456789
- 粉丝: 65
- 资源: 5万+
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 利用迪杰斯特拉算法的全国交通咨询系统设计与实现
- 全国交通咨询系统C++实现源码解析
- DFT与FFT应用:信号频谱分析实验
- MATLAB图论算法实现:最小费用最大流
- MATLAB常用命令完全指南
- 共创智慧灯杆数据运营公司——抢占5G市场
- 中山农情统计分析系统项目实施与管理策略
- XX省中小学智慧校园建设实施方案
- 中山农情统计分析系统项目实施方案
- MATLAB函数详解:从Text到Size的实用指南
- 考虑速度与加速度限制的工业机器人轨迹规划与实时补偿算法
- Matlab进行统计回归分析:从单因素到双因素方差分析
- 智慧灯杆数据运营公司策划书:抢占5G市场,打造智慧城市新载体
- Photoshop基础与色彩知识:信息时代的PS认证考试全攻略
- Photoshop技能测试:核心概念与操作
- Photoshop试题与答案详解
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)