﻿ C語言編程筆試題（第三十五套）_電腦知識網

# C語言編程筆試題（第三十五套）

2022-06-13   來源: C編程

．學生的記錄由學號和成績組成N名學生的數據已在主函數中放入結構體數組s中請編寫函數fun它的功能是把指定分數范圍內的學生數據放在b所指的數組中分數范圍內的學生人數由函數值返回

#include? <stdioh>

#define ? N?

typedef struct

{

char? num[];

int s;

}? STREC;

int? fun ( STREC? *a STREC *b int l int h )

{

}

main ()

{

STREC? s[N]= {{&#;GA&#;} {&#;GA&#;} {&#;GA&#;} {&#;GA&#;}

{&#;GA&#;} {&#;GA&#;} {&#;GA&#;} {&#;GA&#; }

{&#;GA&#;} {&#;GA&#;} {&#;GA&#;} {&#;GA&#;}

{&#;GA&#;} {&#;GA&#;} {&#;GA&#;} {&#;GA&#;}};

STREC? h[N]tt;

FILE *out;

int? ijn low heigh t;

printf ( &#;Enter integer number low & heigh :? &#;);

scanf (&#;%d%d&#;? &low &heigh );

if ( heigh < low )

{

t=heigh;

heigh=low;

low=t;

}

n=fun (s h low heigh );

printf ( &#;The student &#;s data between %d&#;%d : \n&#; low heigh );

for (i=; i<n; i++)

printf (&#;%s? %d\n&#; h[i] num h[i] s);

printf ( &#;\n&#; );

out=fopen (&#;outdat&#; &#;w&#;);

fprintf ( out &#;%d\n&#; n );

n=fun ( s h );

for (i=; i<n; i++)

for (j=i+; j<n; j++)

if(h[i]s>h[j]s)

{

tt=h[i] ;

h[i]=h[j];

h[j]=tt;

}

for(i=;i<n; i++)

fprintf (out &#;%d\n&#; h[i] s);

fprintf ( out &#;\n&#; );

fclose ( out );

}

．請編寫函數fun該函數的功能是刪去一維數組中所有相同的數使之只剩一個數組中的數已按由小到大的順序排列函數返回刪除後數組中數據的個數

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

# include <stdioh>

# define? N?

int fun(int a[] int n)

{

}

main()

{

int a[N]={} in=;

printf(&#;The original data :\n&#;);

for(i=; i<n; i++)

printf(&#;%d&#;a[i]);

n=fun(an);

printf(&#;\n\nThe data after deleted :\n&#;);

for(i=;i<n;i++)

printf(&#;%d&#;a[i]);

printf(&#;\n\n&#;);

}

．下列給定程序中函數fun的功能是計算n的次方的值(規定n的值大於小於)通過形參指針傳回主函數並計算該值的個位十位百位上數字之和作為函數值返回例如次方是其低位數的和值是

#include <stdioh>

#include <mathh>

int fun(int n int *value)

{

int dsi;

/********found********/

d=;

/********found********/

s=;

for(i=; i<=; i++)

d=d*n;

*value=d;

for(i=; i<=; i++)

{

s=s+d%;

/********found********/

s=s/;

}

return s;

}

main()

{

int n sum v;

do

{

printf(&#;\nEnter n(<n<): &#;);

scanf(&#;%d&#;&n);

}

while(n<= || n>=);

sum=fun(n&v);

printf(&#;\n\nThe result:\n value=%d sum=%d\n\n&#;vsum);

}

．下列給定程序中函數fun的功能是用下面的公式求π的近似值直到最後一項

π? ? ? ?

－≈ － + － &#; － +…

? ? ?

#include <mathh>

#include <stdioh>

float fun(float num)

{

int s;

float ntpi;

t=;

pi=;

n=;

s=;

/********found********/

while (t>=num)

{

pi=pi+t;

n=n+;

s=s;

/********found********/

t=s%n;

}

pi=pi*;

return pi;

}

main( )

{

float nn;

clrscr();

printf(&#;Enter a float number: &#;);

scanf(&#;%f&#; &n);

n=fun(n);

printf(&#;%f\n&#; n);

}

From:http://tw.wingwit.com/Article/program/c/201404/30452.html
推薦文章
Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.