生活随笔 
收集整理的這篇文章主要介紹了
                                
全国计算机等级考试题库二级C操作题100套(第29套) 
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
 
                                
                            第29套:
 
程序通過定義學生結構體變量,存儲了學生的學號、姓名和3門課的成績。函 數fun的功能是對形參b所指結構體變量中的數據進行修改,最后在主函數中輸出修改后的數據。
 
#include  <stdio.h>   
#include  <string.h>   
struct  student 
{  
long  sno
;  
char  name
[ 10 ] ;  
float  score
[ 3 ] ;  
} ;  
void  fun (  struct  student 
* b
)  
{  int  i
;  
b__1__ 
=  10004 ;  
/ 
strcpy ( b__2__
,  "LiJie" ) ;  
}  
main ( )  
{  struct  student t
= { 10002 , "ZhangQi" ,  93 ,  85 ,  87 } ;  
int  i
;  
printf ( "\n\nThe original data :\n" ) ;  
printf ( "\nNo: %ld Name: %s\nScores: " , t
. sno
,  t
. name
) ;  
for  ( i
= 0 ;  i
< 3 ;  i
++ )  printf ( "%6.2f " ,  t
. score
[ i
] ) ;  
printf ( "\n" ) ;  
fun ( __3__
) ;  
printf ( "\nThe data after modified :\n" ) ;  
printf ( "\nNo: %ld Name: %s\nScores: " , t
. sno
,  t
. name
) ;  
for  ( i
= 0 ;  i
< 3 ;  i
++ )  printf ( "%6.2f " ,  t
. score
[ i
] ) ;  
printf ( "\n" ) ;  
}  
 
解題思路:
 
給定程序MODI1.C中函數fun的功能是:應用遞歸算法求形參a的平方根。求平方根的迭代公式如下:
 
#include  <stdio.h>   
#include  <math.h>   
double  fun ( double  a
,  dounle x0
)  
{  double  x1
,  y
;  
x1
= ( x0
+  a
/ x0
) / 2.0 ;  
if (  fabs ( x1
- xo
) > 0.00001  )  y
= fun ( a
, x1
) ;  
else  y
= x1
;  
return  y
;  
}  
main (  )  
{  double  x
;  
printf ( "Enter x: " ) ;  scanf ( "%lf" , & x
) ;  
printf ( "The square root of %lf is %lf\n" , x
, fun ( x
, 1.0 ) ) ;  
}  
 
解題思路:
 
學生的記錄由學號和成績組成,N名學生的數據已在主函數中放入結構體數組s中, 請編寫函數fun,它的功能是:把高于等于平均分的學生數據放在b所指的數組中,高于等于平均分的學生人數通過形參n傳回,平均分通過函數值返回。
 
#include  <stdio.h>   
#define  N 12  
typedef  struct  
{  char  num
[ 10 ] ;  
double  s
;  
}  STREC
;  
double  fun (  STREC 
* a
,  STREC 
* b
,  int  * n 
)  
{  
}  
main ( )  
{  STREC s
[ N
] = { { "GA05" , 85 } , { "GA03" , 76 } , { "GA02" , 69 } , { "GA04" , 85 } ,  { "GA01" , 91 } , { "GA07" , 72 } , { "GA08" , 64 } , { "GA06" , 87 } ,  { "GA09" , 60 } , { "GA11" , 79 } , { "GA12" , 73 } , { "GA10" , 90 } } ;  
STREC h
[ N
] ,  t
; FILE 
* out 
;  
int  i
, j
, n
;  double  ave
;  
ave
= fun (  s
, h
, & n 
) ;  
printf ( "The %d student data which is higher than %7.3f:\n" , n
, ave
) ;  
for ( i
= 0 ; i
< n
;  i
++ )  
printf ( "%s %4.1f\n" , h
[ i
] . num
, h
[ i
] . s
) ;  
printf ( "\n" ) ;  
out 
=  fopen ( "c:\\test\\out.dat" , "w" )  ;  
fprintf ( out
,  "%d\n%7.3f\n" ,  n
,  ave
) ;  
for ( i
= 0 ; i
< n
- 1 ; i
++ )  
for ( j
= i
+ 1 ; j
< n
; j
++ )  
if ( h
[ i
] . s
< h
[ j
] . s
)  { t
= h
[ i
]  ; h
[ i
] = h
[ j
] ;  h
[ j
] = t
; }  
for ( i
= 0 ; i
< n
;  i
++ )  
fprintf ( out
, "%4.1f\n" , h
[ i
] . s
) ;  
fclose ( out
) ;  
}  
 
解題思路:
 
利用for循環計算平均分t。 利用for循環把高于平均分的學生記錄存入b中,人數*n加1。  
double  fun (  STREC 
* a
,  STREC 
* b
,  int  * n 
)  
{  
double  t
= 0  ;  
int  i 
;  
* n 
=  0  ;  
for ( i 
=  0  ;  i 
<  N 
;  i
++ )  t 
=  t 
+  a
[ i
] . s 
;  
t 
=  t 
/  N 
;  
for ( i 
=  0  ;  i 
<  N 
;  i
++ )  if ( a
[ i
] . s 
>  t
)  b
[ ( * n
) ++ ]  =  a
[ i
]  ;  
return  t 
;  
} 
                            總結 
                            
                                以上是生活随笔 為你收集整理的全国计算机等级考试题库二级C操作题100套(第29套) 的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                            
                                如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。