第2章數(shù)據(jù)類型運(yùn)算符和表達(dá)式(完整)_第1頁
第2章數(shù)據(jù)類型運(yùn)算符和表達(dá)式(完整)_第2頁
第2章數(shù)據(jù)類型運(yùn)算符和表達(dá)式(完整)_第3頁
第2章數(shù)據(jù)類型運(yùn)算符和表達(dá)式(完整)_第4頁
第2章數(shù)據(jù)類型運(yùn)算符和表達(dá)式(完整)_第5頁
已閱讀5頁,還剩92頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、南京審計(jì)學(xué)院南京審計(jì)學(xué)院信息科學(xué)與技術(shù)學(xué)院信息科學(xué)與技術(shù)學(xué)院孫玉星孫玉星 2/983/98preprocessor instructionpengisytiharan globlmain ()pengisytiharan setempatstatementglobal declarationlocal declaration4/98#include /*函數(shù)功能函數(shù)功能:計(jì)算兩個(gè)整數(shù)相加之和計(jì)算兩個(gè)整數(shù)相加之和 入口參數(shù)入口參數(shù):整型數(shù)據(jù)整型數(shù)據(jù)a和和b 返回值:返回值: 整型數(shù)整型數(shù)a和和b之和之和*/int add(int a, int b)return (a + b);/*主函數(shù)主函數(shù)*

2、/main()int x, y, sum = 0;printf(input two integers:);scanf(%d%d, &x, &y); /*輸入兩個(gè)整型數(shù)輸入兩個(gè)整型數(shù)x和和y*/sum = add(x, y); /*調(diào)用函數(shù)調(diào)用函數(shù)add計(jì)算計(jì)算x和和y相加之和相加之和*/printf(sum = %dn, sum); /*輸出輸出x和和y相加之和相加之和*/5/986/987/988/989/9810/9811/98example:12/9813/98example:number1?number2?25232314/98algorithm syntax rules:expres

3、sions type must be the same as variables typevalid example:invalid example:15/98example:calculate and display the price of a number of apples if the quantity in kg and price per kg are given.input: and output:process: = * 16/98example:17/98example:quantity? priceperkg? price?4.509.00218/98example:19

4、/9820/98數(shù)據(jù)類型數(shù)據(jù)類型基本類型基本類型構(gòu)造類型構(gòu)造類型指針類型指針類型空類型空類型整型整型實(shí)型(浮點(diǎn)型)實(shí)型(浮點(diǎn)型)字符型字符型枚舉類型枚舉類型數(shù)組類型數(shù)組類型結(jié)構(gòu)體類型結(jié)構(gòu)體類型共用體類型共用體類型單精度實(shí)型雙精度實(shí)型基本整型長整型短整型無符號(hào)整型21/9822/9823/9824/9825/9826/9827/9828/9829/9830/9831/98#include main()printf(data type number of bytesn);printf(- -n);printf(char %dn, sizeof(char);printf(int %dn, sizeo

5、f(int);printf(short int %dn, sizeof(short);printf(long int %dn, sizeof(long);printf(float %dn, sizeof(float);printf(double %dn, sizeof(double);32/98階碼符號(hào)階碼符號(hào)階碼的數(shù)值階碼的數(shù)值尾數(shù)符號(hào)尾數(shù)符號(hào)尾數(shù)的數(shù)值尾數(shù)的數(shù)值階碼階碼j尾數(shù)尾數(shù)s33/9834/9835/9836/98b, 98b, 66b, 98b, 6637/9838/9839/98area = 88.247263circumference = 33.30085440/9841/98

6、42/9843/98example:44/9845/9846/9847/98example:浮點(diǎn)數(shù)除法浮點(diǎn)數(shù)除法floating division or or both are floats整數(shù)除法整數(shù)除法integer division and are integers48/98example:49/98example:50/98example:51/9852/9853/98example:1252102remainderresult54/9855/98example:-73-2-6-1remainderresult56/98example:7-3-261remainderresult57/

7、98example:58/9859/98examples:60/9861/98example: 62/98example:63/9864/9865/98#include main( ) float price, discount, total; printf(“buying price : “); scanf(“%f”, &price); printf(“ndiscount rate : “); scanf(“%f”, &discount); total = price * discount; printf(“the total price is %.2fn”, total);buying p

8、rice: _discount?price? total?buying price: 10.00_10.00buying price: 10.00discount rate: _buying price: 10.00discount rate: 0.25_0.252.50buying price: 10.00discount rate: 0.25_buying price: 10.00discount rate: 0.25the total price is 2.50_example:66/9867/98example:int number, total;float start_x, star

9、t_y;. . . number = total = 0;start_x = start_y = 100.0;total?number?start_x?start_y?00100.0100.068/9869/98example:num = num + 5;num152070/98example:num += 5;71/9872/98operationexamples of expressiondescription+=num += 5;num = num + 5;-=num -= 5;num = num 5;*=num *= 5;num = num * 5;/=num /= 5;num = n

10、um / 5;%=num %= 5;num = num % 5;73/98doublefloatlongunsignedintchar,short低高74/9875/98example: int x = 10;float y;y = (float)x;x10y?10.00000076/98example: int total, number;float average;average = total / number;total15number2average?7.000000兩個(gè)整數(shù)運(yùn)算的結(jié)果兩個(gè)整數(shù)運(yùn)算的結(jié)果還是整數(shù),不是浮點(diǎn)數(shù)還是整數(shù),不是浮點(diǎn)數(shù)77/98example: int tot

11、al, number;float average;average = (float)total / number;total15number2average?7.50000078/98operationdescriptionexamples of expressionvalueless than6 91 (true)=less than or equal to5 greater than2 60 (false)=greater than or equal to9 = 51 (true)=equal to7 = 50 (false)!=not equal to6 != 51 (true)79/98a b = cd = a bch a + 1 d = a + b c3 = x b)= cd = (a b)ch (a + 1)d = (a + b) c)(3 = x) a )a2b5c15d1783/98example: (a = 1) & (b = 5) a2b5c15d1784/98example: (c = ( b * 3 ) ) | (a = 3) a2b5c15d1785/98example: ! ( ( a d ) ) a2b5c15d1786/9887/9888/9889/98example:j = +i - 2i5

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論