当前位置:文档之家› C语言程序设计习题集沈国荣-参考答案

C语言程序设计习题集沈国荣-参考答案

《C语言程序设计》习题解答沈国荣隋雪莉闵芳目录第1章 C语言程序设计概述 (2)第2章数据类型及其运算 (3)第3章语句与输入输出 (4)第4章选择结构程序设计 (6)第5章循环结构程序设计 (9)第6章数组 (12)第7章函数 (15)第8章编译预处理 (18)第9章指针 (19)第10章结构体与共用体 (22)第11章位运算 (26)第12章文件操作 (27)第1章 C语言程序设计概述1. 函数、main()函数2. /*、*/3. .C、.OBJ、.EXE4. 顺序结构、选择结构、循环结构三、编程题1.【参考代码】#include<stdio.h>int main( ){printf( "(学校名称)\n" ) ;printf( "(姓名)\n" ) ;return 0 ;}2.【参考代码】#include<stdio.h>int main( ){printf( "(学校名称)\n(姓名)\n" ) ;return 0 ;}第2章数据类型及其运算注:第5题B选项为:'\'' '\017' '\t'二、填空题1. 字母、数字、下划线2. 1、4、4、83. -164. 3.55. 06. 97. 68. -609. y%2==110. 1、0、1三、程序阅读题1. b2. 03. 04. 10,25. 9,10,9,106. 3,1,0,07. 3,20,30,1第3章语句与输入输出1. 123.472. D3. 回车4. 10,2三、程序阅读题1. 2612. 203. 201,104. y=4630y=46305. *3.140000,3.142*6. c:dec=120,oct=170,hex=78,ASCII=x7. x=1 y=2 *sum*=310 squared is : 1008. 2 48 20.2 20.29. x+y+z=4810. 55, ,A四、编程题1.【参考代码】#include<stdio.h>int main( ){char ch;printf("请输入一个字符:\n");scanf("%c",&ch);printf("%c的ASCII码为:%d\n", ch,ch);return 0 ;}2.【参考代码】#include<stdio.h>#define PI 3.1416int main( ){double r, h;double cl,cs,cv;printf("请输入圆的半径:");scanf("%lf", &r);printf("请输入圆柱高:");scanf("%lf", &h);cl=2*PI*r;cs=PI*r*r;cv=PI*r*r*h;printf("圆的周长为:%.4lf\n", cl);printf("圆的面积为:%.4lf\n", cs);printf("圆柱的体积为:%.4lf\n", cv);return 0 ;}3.【参考代码】#include<stdio.h>int main( ){int splitInt,one,ten,hundred;printf("输入要处理的整数:");scanf("%d",&splitInt);hundred = splitInt/100;ten = splitInt%100/10;one = splitInt%10;printf("个位:%d,十位:%d,百位:%d\n",one,ten,hundred);return 0 ;}第4章选择结构程序设计1. 102. 2,2,23. 64. 97,b5. c=-16. 88887. 20,08. 2,19. 1,12,22,1-2,210. a=1,b=3三、程序完善题1. a>b、c>x四、编程题1.【参考代码】#include<stdio.h>int main( ){int a, b, c,d,min;printf("输入4个整数:");scanf("%d%d%d%d",&a,&b,&c,&d);if(a < b) min = a;else min = b;if(c < min) min=c;if(d<min) min=d;printf("%d\n",min);return 0 ;}2.【参考代码】#include<stdio.h>int main( ){int num,a,b,c,d;printf("请输入一个四位整数:");scanf("%d",&num);a=num/1000;b=num%1000/100;c=num%100/10;d=num%10;printf("各位数字之和为:%d\n",a+b+c+d);return 0 ;}3.【参考代码】#include<stdio.h>int main( ){int x;printf("请输入x:");scanf("%d",&x);printf("y的值为:");if(x<0)printf("%d\n",x);else if(x<50)printf("%d\n",3*x-2);else if(x<100)printf("%d\n",4*x+1);elseprintf("%d\n",5*x);return 0 ;}4.【参考代码】#include<stdio.h>int main( ){int dj;float zl,je,yfk;printf("请输入等级(1~4): ");scanf("%d",&dj);if (dj>4||dj<1){printf("无此等级的苹果!\n");return 0;}printf("请输入重量(公斤): ");scanf("%f",&zl);printf("\n");switch (dj){case 1 : je=5.5*zl; break;case 2 : je=4.3*zl; break;case 3 : je=3.0*zl; break;case 4 : je=2.5*zl; break;}printf("您选择苹果级别: %d 级\n",dj);printf("您购买苹果重量: %.2f公斤\n",zl);printf("您应付金额为: %.2f元\n",je);printf("\n");printf("顾客所付金额: ");scanf("%f",&yfk);if (yfk<je){printf("Data Error!\n");return 0;}printf("应找您: %.2f元\n",yfk-je);return 0 ;}第5章循环结构程序设计1. 1,2,02 . m=4,n=23. A2C4E64. 1325. 46. k=0,m=57. x=88. 1.69. 998988三、程序完善题1. ( ch > 'Z' && ch <= 'Z' + 4 ) ||(ch > 'z' ) ch - 262. k k/10 continue3. i + t * 10 s = s + t4. fabs( t ) >= 1e-6 f = -f5. i<10 j%3 !=0四、编程题1.【参考代码】#include<stdio.h>int main( ){int n , i , j , k ;printf( "Output:\n" ) ;for(n = 100 ; n < 1000 ; n++ ){i = n % 10 ; /* 个位*/j = ( n / 10 ) % 10 ; /* 十位*/k = n / 100 ; /* 百位*/if ( n == i * i * i + j * j * j + k * k * k )printf( "%d\n" , n ) ;}return 0 ;}2. 【参考代码】#include<stdio.h>int main ( ){int i , m , n , t , p , k ;printf( "Please input: " ) ;scanf ( "%d,%d" , &m , &n ) ;if( m < n ){t = n ;n = m ;m = t ;}p = m * n ;while ( n != 0 ) /* 余数不为0,继续相除,直到余数为0 */ {i = m % n ;m = n ;n = i ;}k = p / m ;printf( "%d,%d\n" , m , k );return 0 ;}3. 【参考代码】#include<stdio.h>int main( ){int i , n , t , sum ;t = 1 ;sum = 0 ;printf( "Please input: n = " ) ;scanf( "%d" , &n ) ;for( i = 1 ; i <= n ; i++ ){t = t * i ;sum = sum + t ;}printf( "1!+2!+…+%d!= %d\n" , n , sum ) ;return 0 ;}4. 【参考代码】#include<stdio.h>int main( ){int i , m ;double sum = 0 , k = 1 ;printf( "Please input : m=" ) ;scanf( "%d" , &m ) ;for( i = 1 ; i <= m ; i++ ){sum = sum + k / i ;k = -k ;}printf( "sum=%4.2f\n" , sum ) ;return 0 ;}第6章数组1 82 43 0,24 125 t*M6 mo7 fwo三、程序完善题1 k = i j = ia[k] = max a[j] = min2 sum += score[i] score[i]<avg3 s[i] = s[i] + a[i][j] printf( "\n" ) ;4 j = strlen( str ) – 1 str[j] = k5 ( c = getchar( ) ) != '#' num[c-'A'] += 1四、编程题1. 【参考代码】#include<stdio.h>#define N 5int main( ){int a[N] , i , j , r , temp ;printf( "Please input %d numbers\n" , N ) ;for( i = 0 ; i < N ; i++ )scanf( "%d" , &a[i] ) ;for( i = 0 ; i < N - 1 ; i++ ){r = i ;for( j = i + 1 ; j < N ; j++ )if( a[j] < a[r] )r = j ;if( r != i ){temp = a[r] ;a[r] = a[i] ;a[i] = temp ;}}printf( "The array after sort:\n" ) ;for( i = 0 ; i < N ; i++ )printf( "%5d" , a[i] ) ;printf( "\n" ) ;return 0 ;}2. 【参考代码】#include<stdio.h>int main( ){int a[10] = { 1 , 2 , 3 , 6 , 7 , 8 , 9 , 10 } ;int x , j , k = 0 ;printf( "Please input :x= " ) ;scanf( "%d" , &x) ;if( x > a[7] )a[8] = x ;else{for( j = 0 ; j < 8 ; j++ )if( x < a[j] )break ;for(k = 8 ; k > j ; k-- )a[k] = a[k - 1] ;a[j] = x ;}for( j = 0 ; j < 9 ; j++ )printf( "%5d" , a[j] ) ;printf( "\n" ) ;return 0 ;}3. 【参考代码】#include<stdio.h>int main( ){int a[5][5] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21, 22,23,24} ;int i , j ,sum = 0 ;for ( i = 0 ; i < 5 ; i++ ){for ( j = 0 ; j < 5 ; j++)printf( "%4d" , a[i][j] ) ;printf( "\n" ) ;}for( i =0 ;i < 5 ; i++ )sum += a[i][i] ;printf( " sum=%4d\n" , sum ) ;return 0 ;}4. 【参考代码】#include<stdio.h>int main( ){char s1[100] , s2[30] ;int i , j ;printf( "Please input s1:" ) ;gets( s1 ) ;printf( "Please input s2:" ) ;gets( s2 ) ;for( i = 0 ; s1[i] != '\0' ; i++ ) ;for( j = 0 ; s2[j] != '\0' ; j++ , i++ )s1[i] = s2[j] ;s1[i] = '\0' ;printf( "Output\ns1:" ) ;puts( s1 ) ;return 0 ;}5. 【参考代码】#include<stdio.h>int main( ){char s1[100] ;int i ;printf( "Please input s1:" ) ;gets( s1 ) ;for( i = 0 ; s1[i] != '\0' ; i++ ) ;printf( "The length of s1 is %d\n" ,i ) ;return 0 ;}第7章函数1 max is 22 a=1,b=23 1 114 a=11,b=12,c=25 66 7 8 97 8 178 0 1 2 0 1 2三、程序完善题1 float area ( float r ) return s2 z = fun( x , y ) z = z * x3 count =fun( score ) count++四、编程题1. 【参考代码】#include<stdio.h>int main( ){void f(int n) ;int n ;printf( "Please input: n= " ) ;scanf( "%d" , &n ) ;if( n <= 0)printf( "Wrong number!\n" ) ;elsef( n ) ;return 0 ;}void f(int n){if( n % 2 == 1 )printf( "%d is a odd number.\n" , n ) ;elseprintf( "%d is a even number.\n" , n ) ;}2. 【参考代码】#include < stdio.h >#include < math.h >int main( ){void f( int m ) ;int m ;printf( "Please input: m= " ) ;scanf( "%d" , &m ) ;f( m ) ;return 0 ;}void f( int m ){int i , k ;k = sqrt( m );for(i = 2 ; i <= k ; i++ )if( m % i == 0 )break;if (i >= k + 1 )printf( "%d is a Prime Number.\n" , m ) ;elseprintf( "%d is not a Prime Number.\n" , m ) ; }3. 【参考代码】#include<stdio.h>int gys( int m , int n ){int r ;r = m % n ;while( r != 0 ){m = n ;n = r ;r = m % n ;}return n ;}int gbs( int m , int n , int r ){return m * n / r ;}int main( ){int m , n , t ;printf( "Please input(m,n):" ) ;scanf( "%d%d" , &m , &n ) ;if( m < n ){t = m ;m = n ;n = t ;}t = gys( m , n ) ;printf( "gys=%d\n" , t ) ;t = gbs( m , n , t ) ;printf( "gbs=%d\n" , t ) ;return 0 ;}4. 【参考代码】#include<stdio.h>int main( ){void mystrcat( char s1[100] , char s2[30] ) ;char s1[100] , s2[30] ;printf( "Please input s1:" ) ;gets( s1 ) ;printf( "Please input s2:" ) ;gets( s2 ) ;mystrcat( s1 , s2 ) ;printf( "Output\ns1:" ) ;puts( s1 ) ;return 0 ;}void mystrcat( char s1[100] , char s2[30] ){int i , j ;for( i = 0 ; s1[i] != '\0' ; i++ ) ;for( j = 0 ; s2[j] != '\0' ; j++ , i++ )s1[i] = s2[j] ;s1[i] = '\0' ;}第8章编译预处理1 6,182 153 5第9章指针二、填空题1. 地址,NULL(或0)2 . char a, *p; ,scanf("%c", &a); ,p=&a;3. *m4. for( k=0; k<10; k++ )5. *(p+i) ,p[i] ,*(x+i)6. str[i]或*( str + i ) ,i三、程序阅读题1. gae2. bcdABCD3. 7, 8, 84. 8 45. 3 14 26. efgh7. w,one8. 7四、程序完善题1. a[i] 或*( a + i )2. *p!='\0' *p-'0'3. p1 p2-x4. max(int a , int b ); p = max四、编程题1.【参考代码】#include<stdio.h>void sort( int *a , int *b , int *c );int main(){int m , n , t ;printf( "Please input(m n t):" ) ;scanf( "%d%d%d" , &m , &n , &t ) ;sort( &m , &n , &t ) ;printf( "The result is :%d\t%d\t%d\n" , m , n , t ) ;return 0 ;}void sort( int *a , int *b , int *c ){int temp ;if( *a > *b ) { temp = *a ; *a = *b ; *b = temp ; }if( *a > *c ) { temp = *a ; *a = *c ; *c = temp ; }if( *b > *c ) { temp = *b ; *b = *c ; *c = temp ; }}2.【参考代码】程序1:#include <stdio.h>int strcompare( char *str1 , char *str2 );int main( ){int m ;char s1[20] , s2[20] , *p1 , *p2 ;printf( "Please input(string1):" ) ;scanf( "%s" , s1 ) ;printf( "Please input(string2):" ) ;scanf( "%s" , s2 ) ;m = strcompare ( s1 , s2 ) ;printf( "The result of strcompare is: %d\n" , m ) ;return 0 ;}int strcompare( char *str1 , char *str2 ){int i = 0 ;while( ( *( str1 + i ) == *( str2 + i ) ) &&( *( str1 + i ) != '\0' ) ) i++ ;return( *( str1 + i ) - *( str2 + i ) ) ;}程序2:#include <stdio.h>int strcompare( char *str1 , char *str2 );int main( ){int m ;char s1[20] , s2[20] , *p1 , *p2 ;printf( "Please input(string1):" ) ;scanf( "%s" , s1 ) ;printf( "Please input(string2):" ) ;scanf( "%s" , s2 ) ;p1 = s1 ;p2 = s2 ;m = strcompare ( p1 , p2 ) ;printf( "The result of strcompare is: %d\n" , m ) ;return 0 ;}int strcompare( char *str1 , char *str2 ){int i = 0 ;while( ( *( str1 + i ) == *( str2 + i ) ) &&( *( str1 + i ) != '\0' ) ) i++ ;return( *( str1 + i ) - *( str2 + i ) ) ;}程序3:#include <stdio.h>int strcompare( char str1[] , char str2[] );int main( ){int m ;char s1[20] , s2[20] , *p1 , *p2 ;printf( "Please input(string1):" ) ;scanf( "%s" , s1 ) ;printf( "Please input(string2):" ) ;scanf( "%s" , s2 ) ;p1 = s1 ;p2 = s2 ;m = strcompare ( p1 , p2 ) ;printf( "The result of strcompare is: %d\n" , m ) ;return 0 ;}int strcompare( char *str1 , char *str2 ){int i = 0 ;while( ( str1[i] == str2[i] ) &&( str1[i] != '\0' ) )i++ ;return( str1[i]- str2[i] ) ;}第10章结构体与共用体1. 112 . p->next=head->next head->next=p3. p->next三、程序阅读题1. 51,60,212. 163. 1001,ChangRong,1098.0四、程序完善题1. sizeof( struct ps ) 或sizeof( bt )2. p=p->next3. person[i].sex五、编程题1.【参考代码】#define N 3#include <stdio.h>struct student{char num[6] ;char name[8] ;int score[2] ;float ave ;} ;void input( struct student stu[N] ) ;void average( struct student stu[N] ) ;int max( struct student stu[N] ) ;int main( ){int i , j ;struct student stu[N] ;input( stu ) ;average( stu ) ;printf( "No\tName\tScore1\tScore2\tAverage\n" ) ;for( i = 0 ; i < N ; i++ ){printf( "%s\t%s\t" , stu[i].num , stu[i].name ) ;for( j = 0 ; j < 2 ; j++ )printf( "%d\t" , stu[i].score[j] ) ;printf( "%8.2f\n" , stu[i].ave ) ;}i = max( stu ) ;printf( "\nThe max is:\n" ) ;printf( "No\tName\tScore1\tScore2\tAverage\n" ) ;printf( "%s\t%s\t" , stu[i].num , stu[i].name ) ;for( j = 0 ; j < 2 ; j++ )printf( "%d\t" , stu[i].score[j] ) ;printf( "%5.2f\n" , stu[i].ave ) ;return 0;}void input( struct student stu[N]){int i , j ;for(i=0;i<N;i++){printf("\nPlease input No%d student:\n",i+1);printf("No:");scanf("%s",stu[i].num);printf("Name:");scanf("%s",stu[i].name);for(j=0;j<2;j++){printf("score %d:",j+1);scanf("%d",&stu[i].score[j]);}}}void average( struct student stu[N]){int i , j , sum ;for(i=0;i<N;i++){for(j=0 , stu[i].ave = 0 ;j<2;j++)stu[i].ave += stu[i].score[j];stu[i].ave = stu[i].ave / 2 ;}}int max( struct student stu[N]){int i , max , index;max = stu[0].ave ;index = 0 ;for( i = 1 ; i < N ; i++ ){if( max < stu[i].ave ){max = stu[i].ave ;index = i ;}}return index;}2.【参考代码】#include<stdio.h>#include<stdlib.h>struct node{short int data ;struct node *next ;} ;typedef struct node NODE ;struct node *CreatLink( ) ;void PrintLink( NODE *head ) ;int max( NODE *head );int main( ){NODE *head ;int max_value ;head = CreatLink( ) ;PrintLink( head ) ;max_value = max( head ) ;printf( "The max is:%d\n" , max_value ) ;return 0 ;}struct node *CreatLink( ){NODE *head , *p , *q ;short int num ;head = ( NODE * )malloc( sizeof( NODE ) ) ;head->next = NULL ;p = head ;printf( "Please input( end of -1)!:\n" ) ;scanf( "%d" , &num ) ;while( num != -1 ){q = ( NODE *)malloc( sizeof( NODE ) ) ;q->data = num ;p->next = q ;p = q ;scanf( "%d" , &num ) ;}p->next = NULL ;return head ;}void PrintLink( NODE *head ){NODE *p;p = head->next ;printf( "The data is:\n" ) ;while( p != NULL ){printf( "%4d" , p->data ) ;p = p->next ;}printf( "\n" ) ;}int max( NODE *head ){NODE *p;short int max = -32768;p = head->next ;while( p != NULL ){if( max < p->data )max = p->data ;p = p->next ;}return max ;}第11章位运算1. 0000 11112 . x | ff003. 4 3三、程序阅读题1. 02. 11 223. 0四、编程题1.【参考代码】#include<stdio.h>int main(){short int data , low ,high ;printf( "Please input( short int):" ) ;scanf( "%d" , &data ) ;low = data & 0x00ff ; /* 0x00ff表示低字节全1 */high = data & 0xff00 ; /* 0xff00表示高字节全1 */printf( "data:0x%x,the value of low byte is:0x%x\n" , data , high ) ;printf( "data:0x%x,the value of high byte is:0x%x\n" , data , low ) ;return 0 ;}2.【参考代码】#include <stdio.h>int main( ){short int data , result ;printf( "Please intput(short int):" ) ;scanf( "%d" , &data ) ;result = data ^ 0x000f ; /* 0x000f表示低4位全1,高12位全0 */ printf( "The data is 0x%x \nThe result is :0x%x\n" , data,result ) ;return 0 ;}第12章文件操作二、填空题1. 二进制ASCII(文本)2 . FILE *fp # include <stdio.h>3. n – 1 buf的首地址4. 15. 用以获得文件读写位置标记指针的位置,函数返回值为当前文件读写位置标记指针相对于文件开头的字节数6. 使文件读写位置标记指针重新返回文件的开头三、程序阅读题1. 1 22. end3. 34. hello,四、程序完善题1. ! feof (fp) fgetc (fp)2. fopen (“num.dat”,”r”) fp,”%d”,&temp z++3. ( ch=getchar() ) ch , fp五、编程题1.【参考代码】#include<stdio.h>#include<stdlib.h>#include<string.h>int main( ){FILE *fp ;char str[100] , filename[10] ;int i = 0 ;if( ( fp = fopen( "upper.txt" , "w+" ) ) == NULL ){printf( "Cannot open file!\n" ) ;exit( 0 ) ;}printf( "Please input(string):\n" ) ;gets( str ) ;while( str[i] != '!' ){if( str[i] >= 'a' && str[i] <= 'z' )str[i] = str[i] - 32 ;fputc( str[i] , fp ) ;i++ ;}rewind( fp ) ;fgets( str , strlen( str ) + 1 , fp ) ;printf( "\nThe result is :\n" ) ;printf( "%s\n" , str ) ;fclose( fp ) ;return 0 ;}2.【参考代码】#include<stdio.h>#include<stdlib.h>#define N 5struct student{char num[10] ;char name[8] ;int score[3] ;float ave ;} stu[N] ;int main( ){int i , j , sum ;FILE *fp ;for( i = 0 ; i < N ; i++ ){printf( "\nPlease input student information: \n" , i + 1 ) ;printf( "No:" ) ;scanf( "%s" , stu[i].num ) ;printf( "Name:" ) ;scanf( "%s" , stu[i].name ) ;sum = 0 ;for( j = 0 ; j < 3 ; j++ ){printf( "Score%d:" , j + 1 ) ;scanf( "%d" , &stu[i].score[j] ) ;sum += stu[i].score[j] ;}stu[i].ave = sum / 3.0 ;}if( ( fp = fopen( "stud.dat" , "w" ) ) == NULL ){printf( "cannot open stud for write!\n" ) ;exit( 0 ) ;}for( i = 0 ; i < N ; i++ ){fwrite( &stu[i] , sizeof( struct student ) , 1 , fp ) ;}fclose( fp ) ;if( ( fp = fopen( "stud.dat" , "r" ) ) == NULL ){printf( "cannot open stud for read!\n" ) ;exit( 0 ) ;}printf( "\nNo\tName\tScore1\tScore2\tAverage\n" ) ;for( i = 0 ; i < N ; i++ ){fread( &stu[i] , sizeof( struct student ) , 1 , fp ) ;printf( "\n%s\t%s\t%d\t%d\t%5.2f\n" , stu[i].num , stu[i].name , stu[i].score[0] , stu[i].score[1] , stu[i].score[2] ,stu[i].ave ) ;}fclose( fp ) ;return 0 ;}3.【参考代码】#include<stdio.h>#include<stdlib.h>#define N 5struct student{char num[10] ;char name[8] ;int score[3] ;float ave ;} stu[N] ;int main( ){int i , j , min , index ;FILE *fp ;struct student temp ;/*从stud.dat文件中读入数据,存放在stu数组中*/if( ( fp = fopen( "stud.dat" , "r" ) ) == NULL ){printf( "cannot open stud for read!\n" ) ;exit( 0 ) ;}printf( "\nThe data is :" ) ;printf( "\nNo\tName\tScore1\tScore2\tAverage\n" ) ;for( i = 0 ; i < N ; i++ ){fread( &stu[i] , sizeof(struct student ) , 1 , fp ) ;printf( "\n%s\t%s\t%d\t%d\t%5.2f\n" , stu[i].num , stu[i].name , stu[i].score[0] , stu[i].score[1] , stu[i].score[2] ,stu[i].ave ) ;}fclose( fp ) ;/*对stu数组中数组元素按其平均值数据域排序*/for( i = 0 ; i < N -1 ; i++ ){min = stu[i].ave ;index = i ;for( j = i + 1 ; j < N ; j++ ){if( min > stu[j].ave )index = j ;}if( index != i ){temp = stu[i] ;stu[i] = stu[index] ;stu[index] = temp ;}}/*将排序之后的stu数组存放在stu_sort文件中*/if( ( fp = fopen( "stu_sort.dat" , "w" ) ) == NULL ){printf( "cannot open stud for write!\n" ) ;exit( 0 ) ;}for( i = 0 ; i < N ; i++ ){fwrite( &stu[i] , sizeof(struct student) , 1 , fp ) ;}fclose( fp ) ;/*将stu_sort文件中的数据,读出存放在stu数组中*/if( ( fp = fopen( "stu_sort.dat" , "r" ) ) == NULL ){printf( "cannot open stud for read!\n" ) ;exit( 0 ) ;}printf( "\nThe result is:" ) ;/*将stu数组中的数据输出*/printf( "\nNo\tName\tScore1\tScore2\tAverage\n" ) ;for( i = 0 ; i < N ; i++ ){fread( &stu[i] , sizeof(struct student) , 1 , fp ) ;printf( "\n%s\t%s\t%d\t%d\t%5.2f\n" , stu[i].num , stu[i].name , stu[i].score[0] , stu[i].score[1] ,stu[i].score[2] , stu[i].ave ) ;}fclose( fp ) ;return 0 ;}。

相关主题