C语言编程学习课件 (10).pdf

上传人:刘静 文档编号:57971770 上传时间:2022-11-06 格式:PDF 页数:20 大小:1.28MB
返回 下载 相关 举报
C语言编程学习课件 (10).pdf_第1页
第1页 / 共20页
C语言编程学习课件 (10).pdf_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《C语言编程学习课件 (10).pdf》由会员分享,可在线阅读,更多相关《C语言编程学习课件 (10).pdf(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Programming In CProgramming In C Programming In CProgramming In C The movie“Roaring Across the Horizon”Programming In CProgramming In C in mathematics you use x for multiplication,in C you use*.The*is used rather than to avoid any possible confusion with a variable called x.Note also that/,rather th

2、an,is used for division.Programming In CProgramming In C#include stdio.h void main()char s=7;int n=4;printf(7/4=%dn,s/n);printf(7.0/4=%fn,(float)s/n);outputoutput:7/4=1 7/4=1 not 1.75not 1.75 7.0/4=1.750000 7.0/4=1.750000 Programming In CProgramming In C The remainder operation is very interesting i

3、n C.The remainder operation is very interesting in C.The remainder is also called the modulus.Each time the hour hand reaches the 12 oclock,and it indicates that it has rotated once and the modulus becomes 0.Starting from 0,the modulus will increase by 1 in turn.Therefore,the modulus of the hour han

4、d ranges from 0 to 11;the modulus of the minute hand ranges from 0 to 59.Programming In CProgramming In C#include stdio.h#include math.h void main()char s=A,t;/generate the random capital letter t=s+rand()%26;printf(s=%c,t=%cn,s,t);Programming In CProgramming In C#include stdio.h#include math.h void

5、 main()char s=a,t;/generate the random lowercase letter t=s+rand()%26;printf(s=%c,t=%cn,s,t);Programming In CProgramming In C#include stdio.h#include math.h void main()char s=0,t;/generate the numeric symbols t=s+rand()%10;printf(s=%c,t=%cn,s,t);Programming In CProgramming In C How to simulate and g

6、enerate a license plate number in How to simulate and generate a license plate number in Kunming?Kunming?The modulus operation has not only the special operators,but also the restrictions on the two operands involved in the operation.It can only operate on integers,that is,integer and data of charac

7、ter type can find the modulus.The floating numbers cannot find the modulus.Find the modulus for a negative number,and the sign of the result is the same as the number before the percent.Programming In CProgramming In C -7%2 :-1 15%-4:3 With the operations of division and modulus,how to take out the

8、With the operations of division and modulus,how to take out the number of each digit of an integer?number of each digit of an integer?518/100 5 518/10%10 1 518%10 8 Type conversions and casts When doing calculations involving mixed data types,C ranks the data types in this order:promotion or widenin

9、g of the data For calculations involving mixed data types,C automatically converts the value in the lower data type to a higher type.Promotion will cause no loss of data,because the higher data types occupy more memory than the lower types and can therefore hold the data precisely.Type conversions a

10、nd casts Sometimes the automatic type conversion does not conform to our calculation intention.It requires the use of cast operations.(dataType)expression (float)(s/4)(float)s/4 1.000000 1.750000 Note:The operand of the cast operation is the value of the expression,not the variable itself.Operator p

11、recedence Consider the following statement:2+7 *8=72 var 2+7 *8=58 var Operator precedence 1)*,/have a higher priority than+、-2)Expressions containing operators of the same precedence are evaluated according to their associativity 3)use()()to change the order of evaluation Programming In CProgrammin

12、g In C#include stdio.h void main()char d=0;int a=9,b=-5,c=23;float x;x=(a*a+c/b)%d-3.5f/(d-20);printf(x=%fn,x);x=(a*a+c/b)%d-3.5f/(d-20);(9*9+23/-5)%48-3.5/(48-20)(81+23/-5)%48-3.5/(48-20)(81-4)%48-3.5/(48-20)77%48-3.5/(48-20)29-3.5/(48-20)29-3.5/28 29-0.125 28.875 Programming In CProgramming In C T

13、he common mathematical operations,such as square root,exponent,logarithm and trigonometric function,there are standard library functions in C to complete the corresponding calculations.We only need to call library functions correctly in expressions during programming.When calling a library function,

14、the function name must be correct,and the data type,number,and order of the arguments must be consistent with the system regulations.The function name is provided by the system.Programming In CProgramming In C Before calling a standard library function,you usually use precompiled commands to include

15、 the header file of the function in the source codes.sqrt(n)sqrt(n)pow(a,b)pow(a,b)fabs(x)fabs(x)sin(x)sin(x)rand()rand()#include “math.h”Programming In CProgramming In C Function Description Example Returned value Comments sqrt(x)Square root of x sqrt(16.000)4.000000 An integer values of x results

16、in a complier error pow(x,y)x raised to the y power(xy)pow(2,3)pow(81,.5)8.000000 9.000000 Integer values of x and y are permitted exp(x)e raised to the x power(ex)exp(-3.2)0.040762 An integer value of x results in a complier error Programming In CProgramming In C Function Description Example Return

17、ed value Comments log(x)Natural log of x base e log(18.697)2.928363 An integer value of x results in a complier error log10(x)Common log of x base 10 log(18.697)1.271772 An integer value of x results in a complier error fabs(x)Absolute value of x fabs(-3.5)3.5000000 An integer value of x results in

18、a complier error abs(x)Absolute value of x fabs(-2)2 An floating-point value of x return a value of 0 Programming In CProgramming In C#define PI 3.14159 ps=2*cos(2*PI/3*(a+b)*sin(PI/2*(a-b);x=(-b+sqrt(b*b-4*a*c)/(2*a);The symbols in the C expressions are written on one line,without subscripts,exponents,fractional line and other forms.The multiplication sign in algebra can be omitted,but*must be written in C expressions.Only parentheses can be used to change the precedence,not brackets or braces.Programming In CProgramming In C

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁