C C

Similar documents
C/C++语言 - C/C++数据

C

CC213

C/C++程序设计 - 字符串与格式化输入/输出

C 1

新版 明解C言語入門編

新・解きながら学ぶC言語

C

新・明解C言語入門編『索引』

untitled

C/C++ - 函数

C/C++ - 字符输入输出和字符确认

C/C++语言 - 分支结构

C/C++ - 文件IO

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

C/C++ 语言 - 循环

C/C++语言 - 运算符、表达式和语句

untitled

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

新版 明解C++入門編

3.1 num = 3 ch = 'C' 2

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

C

C/C++ - 数组与指针

51 C 51 isp 10 C PCB C C C C KEIL

Microsoft Word - CPE考生使用手冊 docx

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

CC213

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

CC213

nooog

CHAPTER VC#

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

chap07.key

C/C++ - 字符串与字符串函数

Ps22Pdf

C++ 程式設計

プログラムの設計と実現II

FY.DOC

Microsoft PowerPoint - STU_EC_Ch02.ppt

untitled

untitled

c_cpp

C/C++ - 结构体、共用体、枚举体

C语言的应用.PDF

Microsoft Word - 第3章.doc

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

_汪_文前新ok[3.1].doc

CHAPTER 1

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

untitled

untitled

新・解きながら学ぶJava

《C语言程序设计》教材习题参考答案

The return of scanf The number of fields successfully converted and assigned int a =1, b =2, c =3; int n = scanf("%d %d %d", &a, &b, &c); printf("%d\n

Ps22Pdf

2015年计算机二级(C语言)模拟试题及答案(四)

第3章.doc

untitled

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

Microsoft Word - C-pgm-ws2010.doc

untitled

Microsoft PowerPoint - ds-1.ppt [兼容模式]

碩命題橫式

untitled

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

华恒家庭网关方案

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

untitled

,,,,,,,,,, ( http: \ \ www. ncre. cn,, ) 30,,,,,,,, C : C : : 19 : : : /16 : : 96 : : : ISBN 7

Microsoft PowerPoint - C_Structure.ppt

第一章

untitled

untitled

1

Microsoft Word - 095_ 什麼最快樂 (白話與經文加註)-ok .doc

ebook39-5

download.kaoyan.com_2006ÄêÌì½ò¹¤Òµ´óѧ¸ß¼¶ÓïÑÔ³ÌÐòÉè¼Æ£¨409£©¿¼ÑÐÊÔÌâ

C

数据结构与算法 - Python基础

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

了 波 涛 和 号 声 袁 读 者 很 容 易 就 进 入 广 州 城 的 水 上 旅 途 袁 进 入 一 座 野 水 上 名 城 冶 的 传 说 中 去 遥 于 是 袁 一 座 名 城 往 事 充 满 了 漂 流 感 袁 旋 律 自 水 上 而 来 袁 我 们 就 这 样 来 到 了 往 事 的

壹、摘 要

02


"# $ % & $# $ % & "!! " # $! %(() * )(

第7章-并行计算.ppt

<4D F736F F D20B9F9B0EABBCDBBAFAB48DEB3B4C1A5BDB3F8A7692E646F63>

Microsoft Word - 01.DOC

PIC_SERVER (11) SMTP ( ) ( ) PIC_SERVER (10) SMTP PIC_SERVER (event driven) PIC_SERVER SMTP 1. E-

untitled

Microsoft Word - 09.數學 docx

extend

$$% % $ (%) % %$ $ ( *+,)(-)-./0-1//0- %) %) % - $%2)33%0 $ % ((3./. 3/3 )3 / % (()33(1 % (()3(/ %89856%:;< % (()3 0()0 3 (. <<=330(<</ 3 3. ()

PowerPoint Presentation

科学计算的语言-FORTRAN95

液晶之家论坛-

Transcription:

C C 2017 3 8

1. 2. 3. 4. char 5. 2/101 C

1. 3/101 C

C = 5 (F 32). 9 F C 4/101 C

1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include<stdio.h> 3 int main(void) 4 { 5 float fah, cel; 6 printf("please input the Fah temperature:\n"); 7 scanf("%f", &fah); 8 cel = (fah - 32.) * 5./9.; 9 printf("%.2f F = %.2f C\n", fah, cel); 10 return 0; 11 } 5/101 C

$ gcc fah2cel.c $./a.out Please input the Fahrenheit temperature: 78 78.00 F = 25.56 C 6/101 C

float fah, cel; float %f %.2f scanf %f scanf &fah fah fah 7/101 C

scanf() printf() scanf() printf() 8/101 C

2. 9/101 C

1. 2. 10/101 C

12 0-3 3.1415-1.23 a b 11/101 C

12/101 C

C 12/101 C

#define #define 13/101 C

price.c 1 #include<stdio.h> 2 #define PRICE 100 3 int main(void) 4 { 5 int num, total; 6 num = 10; 7 total = num * PRICE; 8 printf("total=%d\n", total); 9 return 0; 10 } 14/101 C

15/101 C

16/101 C

a 3 17/101 C

18/101 C

42 42.0 19/101 C

int signed _Bool long void _Complex short unsigned char float double _Imaginary 20/101 C

int long short unsigned signed char # $ % * float double long double _Bool true false _Complex _Imaginary 21/101 C

3. 22/101 C

1. 2. 1 23/101 C

0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 : 10 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 10 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1-10 : -10 24/101 C

int int 25/101 C

int 1 // int_max_min.c: print INT_MIN and INT_MAX 2 #include<stdio.h> 3 #include<limits.h> 4 int main(void) 5 { 6 printf("range of int is %d ~ %d\n", INT_MIN, INT_MAX); 7 printf("sizeof int = %lu bytes\n", sizeof(int) ); 8 return 0; 9 } 26/101 C

int $ gcc int_max_min.c $./a.out range of int is -2147483648 ~ 2147483647 sizeof int = 4 bytes 27/101 C

int int int var; int var1, var2; int 28/101 C

int int 1. int n; n = 1; 2. scanf int n; scanf("%d", &n); 3. int n = 1; 29/101 C

int int a = 1; int b = 2, c = 3; int d, e = 4; // valid, but not good 30/101 C

int 31/101 C

int int a; int b=2; a 2 b : 31/101 C

int 1 // print1.c: display some properties of printf() 2 #include<stdio.h> 3 int main(void) 4 { 5 int a = 10; 6 int b = 2; 7 printf("doing it right: "); 8 printf("%d - %d = %d\n", a, b, a-b); 9 printf("doing it wrong: "); 10 printf("%d - %d = %d\n", a); 11 return 0; 12 } 32/101 C

int $ gcc print1.c $./a.out Doing it right: 10-2 = 8 Doing it wrong: 10-73832 = 771 33/101 C

int print a %d %d printf 34/101 C

C 0x 0X 16 0x10 0X10 0 16 020 35/101 C

1 // bases.c: print 100 in decimal, octal and hex 2 #include <stdio.h> 3 int main(void) 4 { 5 int x = 100; 6 printf("dec = %d; octal = %o; hex = %x\n", x, x, x); 7 printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x); 8 return 0; 9 } 36/101 C

$ gcc bases.c $./a.out dec = 100; octal = 144; hex = 64 dec = 100; octal = 0144; hex = 0x64 37/101 C

%d %o %#o %x %X %#x %#X 38/101 C

C 3 int short long unsigned 39/101 C

short (int) %hd,%ho,%hx long (int) %ld,%lo,%lx long long (int) C99 %lld,%llo,%llx 40/101 C

unsigned %u (int) 16 0-65535 unsigned C90 %lu long (int) unsigned long long (int) C99 %llu 41/101 C

signed short short int signed short signed short int 42/101 C

C short int long int CPU long int short 43/101 C

44/101 C

1 #include <stdio.h> 2 #include <limits.h> 3 int main(void) 4 { 5 int i = INT_MAX; 6 unsigned int j = UINT_MAX; 7 printf("i = %d, i+1 = %d, i+2 = %d\n", 8 i, i+1, i+2); 9 printf("j = %u, j+1 = %u, j+2 = %u\n", 10 j, j+1, j+2); 11 return 0; 12 } 45/101 C

$ gcc IntOverflow.c $./a.out i = 2147483647, i+1 = -2147483648, i+2 = -2147483647 j = 4294967295, j+1 = 0, j+2 = 1 46/101 C

unsigned int 0 int -2147483648 47/101 C

4. char 48/101 C

char char char a, b, =, +,? char 49/101 C

char char char ASCII 5 5 5 char 50/101 C

char char a, b; char c; 51/101 C

A grade char grade = A ; 52/101 C

char grade; grade = A ; grade = A; grade = "A"; grade = 65; // char // // // // A 53/101 C

ASCII 54/101 C

char a = x ; char b = y ; x y ASCII 120 121 a b a: 0 1 1 1 1 0 0 0 b: 0 1 1 1 1 0 0 1 55/101 C

C 56/101 C

printf() %c %d 57/101 C

1 // charcode.c: displays code number for a char 2 #include <stdio.h> 3 int main(void) 4 { 5 char c; 6 printf("please input a character:\n"); 7 scanf("%c", &c); 8 printf("the code for %c is %d\n", c, c); 9 return 0; 10 } 58/101 C

$ gcc charcode.c $./a.out Please input a character: A the code for A is 65 59/101 C

ch 0 1 0 0 0 0 1 1 %c %d A 65 60/101 C

5. 61/101 C

1 000 000 000 1.0 10 9 1.0e9 123 000 1.23 10 5 1.23e5 322.56 3.2256 10 2 3.2256e2 0.000 056 5.6 10 5 5.6e-5 62/101 C

C float double long double 63/101 C

C float 32 6 10 37 10 +37 double 64 10 float C long double double IEEE float IEEE R32.24 double IEEE R64.53 64/101 C

1. (sign) 0 1 2. (exponent) 3. (mantissa) 65/101 C

32 1 8 23 30 22 0 : float 66/101 C

64 1 62 11 51 52 0 : double 67/101 C

R32.24 R64.53 120.5 1110110.1 1.1101101 2 6 68/101 C

1. 2 n. 1 23 24 69/101 C

24 (9) 10 = (1001) 2, 1 24 float 6 70/101 C

8-127 128 +127 71/101 C

8.25 1. 8.25 1.0001 2 3 72/101 C

8.25 1. 8.25 1.0001 2 3 2. 0 3 + 127 = 130 = (1000 0010) 2 (0001) 2 72/101 C

8.25 1. 8.25 1.0001 2 3 2. 0 3 + 127 = 130 = (1000 0010) 2 (0001) 2 3. 0 1000 0010 000 1000 0000 0000 0000 0000 130 = 3 + 127 000 1 1.0001 2 3 72/101 C

120.5 1. 120.5 1.1101101 2 6 73/101 C

120.5 1. 120.5 1.1101101 2 6 2. 0 6 + 127 = 133 = (1000 0101) 2 (1101101) 2 73/101 C

120.5 1. 120.5 1.1101101 2 6 2. 0 6 + 127 = 133 = (1000 0101) 2 (1101101) 2 3. 0 1000 0010 110 1101 0000 0000 0000 0000 133 = 6 + 127 110 1101 1.1101101 2 6 73/101 C

01000010111001011000000000000000, 74/101 C

1. 0 1000 0101 110 0101 1000 0000 0000 0000 75/101 C

1. 0 1000 0101 110 0101 1000 0000 0000 0000 2. 0 (1000 0101) 2 = 133 133 127 = 6 (1.1100101 2 6 ) 2 = (1110010.1) 2 = 114.5. 75/101 C

1 // float_double.c: 2 #include <stdio.h> 3 int main(void) 4 { 5 float f1 = 2.2, f2 = 2.25; 6 double g1, g2; 7 g1 = (double) f1; 8 g2 = (double) f2; 9 printf("g1 = %.13f, g2 = %.13f\n", g1, g2); 10 return 0; 11 } 76/101 C

$ gcc float_double.c $./a.out g1 = 2.2000000476837, g2 = 2.2500000000000 77/101 C

2.2 2.25 78/101 C

2.25 0 1000 0001 001 0000 0000 0000 0000 0 1000 0001 001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 79/101 C

2 0. 2 2 0. 4 0 2 0. 8 0 2 1. 6 1 2 1. 2 1 2 0. 4 0 80/101 C

2.2 10.0011 0011 0011 0011 0011... 81/101 C

2.2 0 1000 0001 000 1100 1100 1100 1100 0 1000 0001 000 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 1100 82/101 C

e E 10-1.56E+12, 2.87e-3 83/101 C

+2.87e-3 2.87e-3 2E5 19.28 2 // is an integer 3.e12.45E-5 84/101 C

1.56 E+12 // wrong double some float some = 4.0 * 2.0; 4.0 2.0 double 64 float 85/101 C

f F float 2.3f 3.4e9F l L long double l 1 L 54.3l 4.3E9L 86/101 C

1 // float1.c: What is the output? 2 #include<stdio.h> 3 int main(void) 4 { 5 float x = 0.1; 6 if (x == 0.1) 7 printf("if\n"); 8 else if (x == 0.1f) 9 printf("else IF\n"); 10 else 11 printf("else\n"); 12 } 87/101 C

$ gcc float1.c $./a.out ELSE IF 88/101 C

$ gcc float1.c $./a.out ELSE IF x 0.1 0.1f 0.1 0.1f 0.1 0.1!= 0.1f x == 0.1f 88/101 C

1 // float2.c: What is the output? 2 #include<stdio.h> 3 int main(void) 4 { 5 float x = 0.1; 6 printf("%lu %lu %lu\n", sizeof(x), sizeof(0.1), sizeof(0.1f)); 7 return 0; 8 } 89/101 C

$ gcc float2.c $./a.out 4 8 4 90/101 C

$ gcc float2.c $./a.out 4 8 4 90/101 C

1 // float3.c: What is the output? 2 #include<stdio.h> 3 int main(void) 4 { 5 float x = 0.5; 6 if (x == 0.5) 7 printf("if\n"); 8 else if (x == 0.5f) 9 printf("else IF\n"); 10 else 11 printf("else\n"); 12 } 91/101 C

$ gcc float2.c $./a.out IF 92/101 C

$ gcc float2.c $./a.out IF x 0.5 0.1f 0.5 0.5f 0.5 0.5 == 0.5f x == 0.5 92/101 C

%f float double %e %Lf %Le long double 93/101 C

1 // showf_pt.c: 2 #include <stdio.h> 3 int main(void) 4 { 5 float a = 32000.; 6 double b = 2.14e9; 7 long double c = 5.32e-5; 8 printf("%f can be written as %e\n", a, a); 9 printf("%f can be written as %e\n", b, b); 10 printf("%lf can be written as %Le\n", c, c); 11 return 0; 12 } 94/101 C

$ gcc showf_pt.c $./a.out 32000.000000 can be written as 3.200000e+04 2140000000.000000 can be written as 2.140000e+09 0.000053 can be written as 5.320000e-05 95/101 C

1 #include <stdio.h> 2 #include <limits.h> 3 int main(void) 4 { 5 float toobig = 1e39; 6 printf("toobig = %f\n",toobig); 7 return 0; 8 } 96/101 C

$ gcc float_overflow.c $./a.out toobig = inf 97/101 C

overflow C inf 98/101 C

1 #include <stdio.h> 2 int main(void) 3 { 4 float a,b; 5 a = 2.e20 + 1; 6 b = a - 2.e20; 7 printf("b = %f\n", b); 8 return 0; 9 } 99/101 C

$ gcc float_err.c $./a.out b = 4008175468544.000000 100/101 C

2.0e20 1 21 21 float 6 7 101/101 C