C语言试题

拈花ヽ惹草 提交于 2020-02-12 00:26:13
 

1.设x的值为15,n的值为2,则表达式x%=(n+=3)运算后,x的值为(  )。

2.设 int a=7,b=9,t;执行完表达式t=(a>b)?a:b后,t的值是(    )。

3.下面程序段的输出结果是(        )。

      int a=1234; a=a&0377; printf(“%d %o"n”,a,a);

4.a数组定义如下,按照内存排列顺序,a数组中的所有元素是(            )。

      char a[3];

8.C语言中调用(    )函数打开文件,调用(   )函数关闭文件,调用(     )函数可实现文件的随机读写。

9.若有int a[3]={10,12,30};则a+1是(    )的地址,*(a+2)=(   )。

二 判断对错(5分,对的划“√”,错的划“×”)

1.在Turbo C中,整型数据在内存中占2个字节。( )

2.表达式1/4+2.75的值是3。( )

3.结构体类型只有一种。( )

4.函数若无返回值,则它一定无形参。( )

5.C语言只能处理文本文件和二进制文件。( )

三 选择题(20分)

1.设 int a=12; 表达式a+=a-=a*=a的值是(  )。

   A 12      B 144      C 0      D 132

2.以下程序的输出结果是(  )。

 main( )

 { int a=011;

printf(“%d"n”,++a);

}

A 12     B 11        C 10      D 9

4.下面的选项中正确的赋值语句是(char a[5],*p=a;)(  )。

   A p=“abcd”;        B a=“abcd”;     C *p=“abcd”;       D *a=“abcd”;

5.若k为整形,则while循环执行(  )次。

   k=2; 

while(k==0)

{ printf(“%d”,k);   k--; printf(“"n”);}

  A 10       B 9    C 0     D 1

6.数组名作为实参传递给形参时,数组名被处理为(  )。

A 该数组的长度 B 该数组的元素个数 C 该数组的首地址 D 该数组中各元素的值

8.若有以下程序段,则值为6的表达式是(   )。

     struct st{ int n;struct st *next;};

     static struct st a[3]={5,&a[1],7,&a[2],9,‘"0’},*p; p=&a[0];

A p++->n       B p->n++    C (*p).n++     D ++p->n

四 写出下列程序的运行结果。(28分)

1.main( )

{ int a[6]={10,6,23,-90,0,3},i;

     invert(a,0,5);

     for(i=0;i<6;i++) printf(“%d,”,a[i]);

     printf(“"n”);

}

invert(int *s,int i,int j)

{ int t;

     if(i<j)

     { invert(s,i+1j-1);

        t=*(s+i);*(s+i)=*(s+j);*(s+j)=t;

      }

}    

2.f1(int a)

   { int b=0; static int c=3;

      b+=1; c++;

      return(a+b+c);

    }

   main()

   { int a=1,i;

      char s1[10]=“java”,s2[10]=“basic”,s[10];

      for(i=0;i<3;i++)     printf("%d ",f1(a));

      printf(“"n”);

      if(strcmp(s1,s2)) { strcpy(s,s1); puts(s);}

printf(“%d,%s"n”,strlen(s2),strcat(s2,s1));

}

3.#define MAX 100

main()

 { int f[MAX],i,j,k=2,m=5;

for(i=0;i<=m;i++)   f[i]=1; f[k-1]=2;

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

for(j=i-k;j<=i-1;j++) f[i]+=f[j];

      printf("%d%5d%5d"n",k,m,f[m]);

   }

五 阅读下列程序,在    处填入适当内容,使程序完整。(32分)

1.求100~200间的全部素数。

     (1)   

main()

{ int m,k,i,n=0;

 for(m=101;m<=200;m+=2)

 {   if(n%10==0)    printf(""n");

           k=sqrt(m);

           for(i= (2) ;i<=k;i++)     if(m%i==0)      (3) ;

           if(i== (4) )

      { printf("%d ",m);n++;}

   }

}

2.用选择法对数组中的10个字符按由大到小排序。

void sort(  (1)  )

char a[ ]; int n;

{   int i,j,k;

char t;

    for (i=0;i<n-1;i++)

    {     (2) ;

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

           if ( (3) )   k=j;

        t=a[k];a[k]=a[i];a[i]=t;}

}

main( )

{   char s[10];

int i;

    for(i=0;i<10;i++)    scanf(“%c”,&s[i]);

      (4)  ;

    printf(“the sorted array:"n”);

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

      printf(“%c”, (5) );

    printf(“"n”);

}

3×4数组,用指针方法实现将每行中的最小数与第0列元素对调

main()

{ int a[3][4],i,j,*p=a[0];

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

      for(j=0;j<4;j++)     scanf(“%d”,p++);

for(p=&a[0][0];p<a[0]+12; (1) )

        swap(p);

 (2) ;

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

   { for(j=0;j<4;j++)    printf(“%3d”,*p++);

      printf(“"n”);}

}

swap(int   (3) )

{ int min,i,*p2=p1,*p3;

   (4) ;

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

 { if(*p2<*p3) p3=p2;   (5) ;

 }

min=*p1;*p1=*p3;*p3=min;

}

请阅读如下代码:给出运行结果

1

#include <stdio.h>

void main()

{

       float radius=1.5, high=2.0;

       double pi=3.14159, vol;

       /*求体积*/

       vol=pi*radius*radius*high;

       /*输出求出的体积*/

       printf("vol=%7.2f"n",vol);

}

2

#include <stdio.h>

void main()

{

       float radius,high;

       double vol,pi=3.1415926;

       printf("请输入圆柱体底面积的半径和圆柱体的高: ");

       scanf("%f%f",&radius,&high); //从键盘输入两个实数赋给变量10,10

       vol=pi*radius*radius*high; //求体积

       printf("radius=%7.2f, high=%7.2f, vol=%7.2f"n",radius,high,vol);

}

3

#include <stdio.h>

void main()

{

       /* 变量声明和初始化 */

       int a,b,c,d;

       int sum, product;

       float quotient;

       int remainder, minus, increase, decrease;

       a = 15;   

       b = 11;

       c = 25;

       d = 12;

       /* 使用运算符 */

    sum = a + b; /* 加法 */

       minus = a - b; /* 减法 */

       product = a * b; /* 乘法 */

       quotient = a / b; /* 除法 */

       remainder = a % b; /* 求模 */

       increase = ++c;

       decrease = --d;

       /* 显示结果*/

       printf ("和为 %d"n",sum);

       printf ("差为 %d"n",minus);

       printf ("积为 %d"n",product);

       printf ("商为 %f"n",quotient);

       printf ("余数为 %d"n",remainder);

       printf (" 1 后为 %d"n",increase);

       printf (" 1 后为 %d"n",decrease);

}

4

#include <stdio.h>

void main()

{

 int num;

 printf(""n 请输入一个数:");

 scanf("%d",&num);

 if                                       //右侧填空,

        printf(""n 该数能被 5 整除 "n ");

 else

        printf(""n 该数不能被 5 整除 "n ");

}

5

#include <stdio.h>

void main()

{

       long ge,shi,qian,wan,x;

       printf(""n 请输入一个五位整数:");

       scanf("%ld",&x);

                                            //分解出万位数

                                            ; //分解出千位数

                                            ; //分解出十位数

                                            ; //分解出个位数

       if (ge==wan && shi==qian) /*个位等于万位并且十位等于千位*/

              printf(""n 这个数是回文数"n");

       else

              printf(""n 这个数不是回文数"n");

}

6分别给出输入值为:-1-02123456的结果

#include <stdio.h>

void main() 

{

      int value, r_digit;

        value = 0;

        do

        {

               printf(""n请输入一个数:");

               scanf("%d", &value);

               if( value <= 0 )

                      printf("该数必须为正数"n");

        }while( value <= 0 );

        

        printf(""n反转后的数为:");

        do

        {

          r_digit = value % 10;

          printf("%d", r_digit);

          value = value / 10;

        }while( value != 0 );

        printf(""n");

}

7

给出执行结果

#include <stdio.h>

void main ()

{

       int c=0,count=0;

       double f;

       while (c <= 250 && count<10)

       {

              count++;

              printf("%d: ",count);

              f=c * 9 / 5.0 + 32.0;

              printf("C = %d, F = %7.2f"n", c, f);

              c = c + 20;

       }

}

8

填空

#include<stdio.h>

void main ()

{

   int number=5;

   int guess;

   printf ("猜一个介于 1 10 之间的数"n");

   do

   {

        printf("请输入您猜测的数:");

        scanf("%d",&guess);

        if (                       )

        {

               printf("太大"n");

        }

        

        if (                       )

        {

               printf("太小"n");

        }

   } while (guess != number);

   printf("您猜中了! 答案为 %d"n",number);

}

9

给出每条代码的注释

#include <stdio.h>

void main()

{

       int x;

       char i, ans;

       ans = 'y';

       do

       {

              x = 0;

              printf(""n请输入字符序列:");

              fflush(stdin); //清空键盘输入缓冲区

              do {

                     i = getchar ();

                     x++;

              }while (i != '"n');

              printf(""n输入的字符数为: %d", --x);

              printf(""n是否需要输入更多序列 (Y/N)? ");

              ans = getchar();

       }while(ans == 'Y' || ans == 'y');

}

10给出执行结果

#include<stdio.h>

struct complex

{

       double re;//实部

       double im;//虚部

};

struct complex add(struct complex,struct complex);

void main()

{

       struct complex x={6.5,8.9},y={7.1,9.4};

       struct complex z;

       z=add(x,y);

       printf("和为:%5.2lf+i%5.2lf"n",z.re,z.im);

}

struct complex add(struct complex a,struct complex b)

{

       struct complex c;

       c.re=a.re+b.re;

       c.im=a.im+b.im;

       return c;

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!