《第八章数组与字符串》-公开课件.pptVIP

  • 1
  • 0
  • 约9.79千字
  • 约 36页
  • 2019-12-31 发布于广西
  • 举报
字符串应用示例三 if( guess == 0 ) { printf( “\nThere is no %c in the word.\n“, cc ); times??; } else if( guess == 1 ) printf( “\nThat guess is correct.\n“ ); // chech if the conditions to end the game has been reached l = 0; while( l m ){ if( condition[l] == ?1){ k = 0; break; } k = 1; l++; } } // while( ( k == 0 ) ( times != 0 ) ) 字符串应用示例三 if( times == 0 ) { printf( “Poor Man!\nThe word is: “); for( z = 0; z m; z++ ) printf( “%c“, letters[z] ); return; } if( k == 1 ) { printf( “You have guessed the word: “ ); for( z = 0; z m; z++ ) printf( “%c“, letters[z] ); printf( “\nYou win.\n“ ); return; } } 字符串应用示例三 void main() { int a, b, c; char* secret; char* words[20] = { “detail“, “average“ }; char letters[20]; begin(); srand( time(NULL) ); /* produce a random number */ a = rand() % 20; /* as the index of the word */ secret = words[a]; // get the word c = strlen( secret ); // the number of the letters in the word // change string into parameter form for( b = 0; *(secret+b) != ‘\0‘; b++ ) letters[b] = *(secret+b); run( letters, c ); } 作 业 第237页:第二题(编程题) 第2小题 第238页:第二题(编程题) 第6小题 第239页:第二题(编程题) 第10、11小题 谢谢! * 安徽大学计算机教学部 计算机程序设计基础 第八章 数组与字符串 学习目标 理解数据类型及数据在内存中是如何存储的 了解数组的意义及数组的使用方法 了解字符串的意义及字符串的使用方法 8.1 数据类型与数据结构 数据与数据结构的关系 数据结构指数据的组织形式,即数据的抽象机制 数据的逻辑结构:元素间的逻辑关系 线性数据结构与非线性数据结构 数据的物理结构:物理实现方法,与机器有关 顺序方式、链接方式、索引方式、散列方式 数据结构上的操作:检索、插入、删除、排序等 同质复合数据类型:数据元素具有同样相同的性质 8.2 数 组 数组的下标 下标从 0 开始,一般使用半开半闭区间 例:for( i = 0; i n; ++i ) a[i] = i; 数组的内部表示 按维顺序存放 数组的基地址,元素的地址 数组下标越界问题 程序不检查下标越界,为什么? 数组应用示例一 通过键盘输入10个整数,然后逆序打印 #include stdio.h #define E 10 void Get( int a[], int n ); void Reverse( int a[], int n ); void Swap( int a[], int x, int y ); void Print( int a[], int n ); void main(){ int array[E]; Get( array, E ); Reverse( array, E ); Print( array, E ); } 数组应用示例一 void Get( int a[], int n ) { int i; for( i = 0; i n; i++ ) scanf(

文档评论(0)

1亿VIP精品文档

相关文档