亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      自考

      各地資訊
      當(dāng)前位置:華課網(wǎng)校 >> 自考 >> 模擬試題 >> 工學(xué)類 >> C語(yǔ)言程序設(shè)計(jì) >> 文章內(nèi)容

      排行熱點(diǎn)

      • 歷年真題
      • 模擬試題
      • 自考自答

      自學(xué)考試《C語(yǔ)言程序設(shè)計(jì)》復(fù)習(xí)試題及答案_第2頁(yè)

      來(lái)源:華課網(wǎng)校  [2017年1月31日]  【

        【4.31】參考答案:

        #include

        main( )

        { int i,j;

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

        printf("%4d",i);

        printf("\n--------------------------------------\n");

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

        { for(j=1;j<10;j++)

        if(j<10-i) printf(" ");

        else printf( "%4d" , (10-i)*j);

        printf("\n");

        }

        }

        【4.32】參考答案:

        #include "math.h"

        main()

        { int flag=0;

        float a,b,c,s;

        do

        { printf("Please enter a b c:");

        scanf("%f%f%f",&a,&b,&c);

        if(a>b+c || b>a+c || c>a+b)

        flag=1;

        }while(flag);

        s=(a+b+c)/2;

        printf("S=%f",s=sqrt((s-a)*(s-b)*(s-c)));

        }

        【4.33】參考答案:

        #include

        main( )

        { int j;

        long n; /* 使用長(zhǎng)整型變量,以免超出整數(shù)的表示范圍 */

        printf("Please input number:");

        scanf("%ld", &n);

        for(j=999;j>=100;j--)/* 可能取值范圍在999到100之間,j從大到小 */

        if(n%j == 0 ) /* 若能夠整除j,則j是約數(shù),輸出結(jié)果 */

        { printf("The max factor with 3 digits in %ld is: %d.\n",n,j);

        break; /* 控制退出循環(huán) */

        }

        }

        【4.34】參考答案:

        #define E 0.000001

        main()

        { float x,y=1,s=0;

        printf("Please enter x=");

        scanf("%f",&x);

        while(1/y>E)

        { s=s+1/y;

        y=y*x;

        }

        printf("S=%f\n",s);

        }

        【4.35】參考答案:

        #include

        main( )

        { int class1, class2, class3;

        char ch;

        class1=class2=class3=0; /* 初始化分類計(jì)數(shù)器 */

        do

        { ch=getch( );

        switch(ch)

        { case '0': case '1': case '2': case '3': case '4':

        case '5': case '6': case '7': case '8': case '9':

        class1++; break; /* 對(duì)分類1計(jì)數(shù) */

        case '+': case '-': case '*': case '/': case '%': case '=':

        class2++; break; /* 對(duì)分類2計(jì)數(shù) */

        default: class3++; break; /* 對(duì)分類3計(jì)數(shù) */

        }

        }while (ch!= '\\'); /* 字符'\'在C程序中要使用轉(zhuǎn)義符'\\' */

        printf("class1=%d, class2=%d, class3=%d\n", class1, class2, class3);

        }

        【4.36】分析:程序的關(guān)鍵是怎樣判斷一個(gè)單詞。由單詞的定義已知它是用空格、制表符或換行符分隔開的,兩個(gè)字符之間沒有空格、制表符或換行符,則認(rèn)為是一個(gè)單詞中的兩個(gè)字符。

        參考答案:

        #define EOF -1

        #define YES 1

        #define NO 0

        #include

        main( ) /* 對(duì)輸入的行、字符和單詞進(jìn)行計(jì)數(shù)統(tǒng)計(jì) */

        { int c, nl, nc, nw, inword;

        inword=NO; /* inword=NO 已處理的最后一個(gè)字符是空格、\t或\n */

        /* inword=YES 已處理的最后一個(gè)字符不是空格、\t或\n */

        nl=nc=nw=0; /* 行、字符、字計(jì)數(shù)器置0 */

        while((c=getchar())!= EOF)

        { ++nc; /* 進(jìn)行字符計(jì)數(shù) */

        if(c=='\n' )

        ++nl; /* 進(jìn)行行計(jì)數(shù) */

        if(c=='\t'||c=='\n'||c==' ')

        inword=NO;/* 如果讀入的字符是空格、\t或\n,則置inword為NO */

        else /* 讀入的字符不是空格、\t或\n */

        if(inword==NO) /* 如果前一個(gè)字符是空格、\t或\n */

        { inword=YES; /* 則讀入的字符為一個(gè)單詞的第一個(gè)字符*/

        ++nw; /*置inword為YES,進(jìn)行單詞計(jì)數(shù) */

        }

        }

        printf("Lines=%d\nWords=%d\nChars=%d\n",nl,nw,nc); /* 輸出結(jié)果 */

        }

        【4.37】參考答案:

        #define E 0.000001

        #include "math.h"

        main()

        { int i,k=1;

        float x,y,t=1,s,r=1;

        printf("Please enter x=");

        scanf("%f",&x);

        for(s=x,y=x,i=2;fabs(r)>E;i++)

        { t=t*(i-1);

        y=y*x*x;

        k=k*(-1);

        r=k*y/t/(2*i-1);

        s=s+r;

        }

        printf("S=%f\n",s);

        }

        【4.38】參考答案:

        main()

        { int i;

        float s=0;

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

        s=s+i;

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

        s=s+i*i;

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

        s=s+1.0/i;

        printf("Result=%f\n",s);

        }

        【4.39】參考答案:

        main()

        { int i;

        float s=1;

        for(i=1;i<=20 && 1.0/i/(i+1)>0.001;i++)

        s=s+1.0/i/(i+1);

        printf("Result=%f i=%d\n",s,i);

        }

        【4.40】參考答案:

        #include

        main()

        { float x,eps,s,y=0,y0,t;

        int n,j;

        printf("Enter x & eps:");

        scanf("%f%f", &x, &eps);

        n=t=j=1;

        s=x;

        do

        { y0=y;

        if(n%2==0) y=y-s/t;

        else y=y+s/t;

        s *= x*x; /* 求x的乘方 */

        t *= (j+1)*(j+2); /* 求n! */

        j += 2;

        n++;

        }while( fabs(y0-y) > eps ); /* 控制誤差 */

        printf("sin(%f)=%f\n",x,sin(x)); /* 輸出標(biāo)準(zhǔn)sin(x)的值 */

        printf("%d,sin(%f)=%f\n",n,x,y); /* 輸出計(jì)算的近似值 */

        }

        【4.41】參考答案:

        main( )

        { int i,j,num,a[10];

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

        { printf("Enter No. %d:", i+1);

        scanf("%d",&num);

        for(j=i-1;j>=0&&a[j]>num;j--)

        a[j+1]=a[j];

        a[j+1]=num;

        }

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

        printf ("No.%d=%d\n", i+1, a[i]);

        }

        【4.42】參考答案:

        main()

        { int n;

        printf("Please enter n:");

        scanf("%d",&n);

        while(n>0)

        { printf("%d",n%10);

        n=n/10;

        }

        }

        【4.43】參考答案:

        main()

        { int i,n;

        long s1=0,s2=0;

        printf("Please enter N:");

        scanf("%d",&n);

        if(n>=0)

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

        s1=s1+i;

        else

        for(i=n;i>=2*n;i--)

        s1=s1+i;

        i=n;

        if(i>=0)

        while(i<=2*n)

        s2=s2+i++;

        else

        while(i>=2*n)

        s2=s2+i--;

        printf("Result1=%ld result2=%ld\n",s1,s2);

        }

        【4.44】分析:據(jù)題意,階梯數(shù)滿足下面一組同余式:

        x≡1 (mod2)

        x≡2 (mod3)

        x≡4 (mod5)

        x≡5 (mod6)

        x≡0 (mod7)

        參考答案:

        #include

        main()

        { int i=1; /* i為所設(shè)的階梯數(shù) */

        while( !((i%2==1)&&(i%3==2)&&(i%5==4)&&(i%6==5)&&(i%7==0)) )

        ++i; /* 滿足一組同余式的判別 */

        printf("Staris_number=%d\n", i );

        }

        【4.45】參考答案:

        main( )

        { int i,n,a;

        for(i=0; ;i++)

        { if(i%8==1)

        { n=i/8;

        if(n%8==1)

        { n=n/8;

        if(n%8==7) a=n/8;

        }

        }

        if(i%17==4)

        { n=i/17;

        if(n%17==15) n=n/17;

        }

        if(2*a==n)

        { printf("result=%d\n",i);

        break;

        }

        }

        }

      責(zé)編:zhangjing0102