现在的位置: 首页 > 14 二级C语言 > 正文

2011年9月全国二级C上机真题第3~4套

2013年02月25日 14 二级C语言 ⁄ 共 195字 ⁄ 字号 暂无评论
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include  <stdio.h>
#include  <string.h>
#define   N   5
#define   M   8
void fun(char  (*ss)[M])
{
    char  *ps[N],*tp;
    int  i,j,k;
    for(i=0; i<N; i++) ps[i]=ss[i];
    for(i=0; i<N-1; i++)
    {
        /**********found**********/
        k=  _________;
        for(j=i+1; j<N; j++)
            /**********found**********/
            if(strlen(ps[k]) < strlen(______)) k=j;
        /**********found**********/
        tp=ps[i];
        ps[i]=ps[k];
        ps[k]= ___________ ;
    }
    printf("\nThe string after sorting by length:\n\n");
    for(i=0; i<N; i++)  puts(ps[i]);
}
main()
{
    char  ch[N][M]= {"red","green","blue","yellow","black"};
    int  i;
    printf("\nThe original string\n\n");
    for(i=0; i<N; i++)puts(ch[i]);
    printf("\n");
    fun(ch);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <math.h>
 
/************found************/
fun(int n)
{
    double   sum,  s0, s1, s2, s;
    int k;
    sum = 1.0;
    if (n <= 2) sum = 0.0;
    s0 = 0.0;
    s1 = 0.0;
    s2 = 1.0;
    for (k = 4; k <= n; k++)
    {
        s = s0 + s1 + s2;
        sum += sqrt(s);
        s0 = s1;
        s1 = s2;
        s2 = s;
    }
    /************found************/
    return sum
}
 
int main ( )
{
    int n;
    printf("Input N=");
    scanf("%d", &n);
    printf("%f\n", fun(n) );
    return 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
25
26
27
28
29
#include <stdio.h>
#include <math.h>
double fun(double x , int  n)
{
}
 
main()
{
    void NONO();
    printf("%f\n", fun(0.3,10));
    NONO();
}
void NONO ()
{
    /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
    FILE *fp, *wf ;
    int i, n ;
    double s, x ;
    fp = fopen("K:\\k51\\24000403\\in.dat","r") ;
    wf = fopen("K:\\k51\\24000403\\out.dat","w") ;
    for(i = 0 ; i < 10 ; i++)
    {
        fscanf(fp, "%lf,%d", &x, &n) ;
        s = fun(x, n) ;
        fprintf(wf, "%f\n", s) ;
    }
    fclose(fp) ;
    fclose(wf) ;
}

抱歉!评论已关闭.