小测试1和2

1 . 设y是int型变量,请写出判断y为奇数的关系表达  _y%2==0
--------------------------------------------------------------------
2. 以下程序运行后的输出结果是__b_
main()
{ char m;
  m='B'+32; printf("%c",m);
}
--------------------------------------------------------------------
3. 下列描述中不正确的是_C_。 
  A:字符型数组中可以存放字符串
  B:可以对字符型数组进行整体输入、输出
  C:可以对整型数组进行整体输入、输出
  D:不能在赋值语句中通过赋值运算符"="对字符型数组进行整体赋值
--------------------------------------------------------------------
 4. 定义数组 float f[]={2.1,8.2,3.6,4.9};float *fp=f;则*++fp等于( 8.2  ):
--------------------------------------------------------------------
 5. 假设 int p1 = 200, p2 = 150,  x =1150, y = 1150; 则表达式 ( y>x) && ( p1>p2) 的值是:0
--------------------------------------------------------------------
 6. C语言中的基本数据类型包括()( 整型 )(字符型)。
--------------------------------------------------------------------
 7. 若有float f1=2.7,f2=13.5; float *fp=&f1;*fp/=4; fp=&f2;,则*fp的值是(13.5
--------------------------------------------------------------------
8. 假设已经定义一个字符数组],赋给他的初值(xiaowang)的语句是(arr[10]={xiaowang} 
--------------------------------------------------------------------
9. 以下程序的输出结果是__10 10 9 1____。
main()
{  int   x=10,y=10,i;
   for(i=0;x>8 ;y=++i)
   printf("%d   %d  ",x--,y);
}
--------------------------------------------------------------------
10 选择填空:输入n和n个实数,找出他们的最大值和最小值,并将最大值和最小值输出到文件c:\abc.txt中。 
运行示例:
输入n:5↙
输入实数:4 56.8 78.0 13 -12↙
程序运行结束!
【程序】
#include <stdio.h>
#include <stdlib.h>
void main()
{   double x,a,b;
    int i,n;
    FILE *p;
    if ((p=fopen(      1      ))==NULL)
    {    printf("Open file is fail\n");
         exit(0);
    }
    printf("输入n:");
    scanf("%d",&n);
    printf("输入实数: ");
    scanf("%lf",&x);
        2     
    for(i=0; i<n-1;i++){
      scanf("%lf",&x);
      if(a<x) a=x;
      if (b>x)     3     
    }
         4     ;
    fclose(p);
  }
(1)  A、”c:\\abc.txt","w"         B、”c:\\abc.txt","r"
      C、”c:\\abc.txt","write"    D、”c:\\abc.txt","read"
(2)  A、a=b=0;   B、a=b=x;   C、a=0;b=x;  D、 a=x;b=0;
(3)  A、 x=b;     B、b=x;     C、a=b;       D、 b=a;
(4)  A、fprintf(p,"max=%.1f,min=%.1f\n", a,b);
      B、fprintf(abc.txt,"max=%.1f,min=%.1f\n", a,b);
      C、printf(p,"max=%.1f,min=%.1f\n", a,b);
D、printf(abc.txt,"max=%.1f,min=%.1f\n", a,b);
--------------------------------------------------------------------
11. 选择填空:定义判断整数是否为水仙花数的函数。利用判断水仙花数的函数,求100~1000之间所有的水仙花数。水仙花数是指一个三位数,其各位数字的立方和等于该数本身,如:153=13+53+33 
【程序】
#include<stdio.h>
void main()
{  int m;
int  flower(int x);
    for(m=100;m<1000;m++)
       if (     1    ) 
printf("水仙花数:%d\n",m);    
}
     2     
{  int a,b,c,s;

    a=x%10;
    3    
c=x/100;
s=a*a*a+b*b*b+c*c*c;
if (s==x)        4     ;   
   else  return 0;
 }
  (1)  A、flower(int m)==1    B、int flower(int m)==1 
        C、flower(m)==1         D、 flower(x)==1
  (2)  A、void  flower(int x)    B、int flower(int x,int s)
        C、int  flower(int x)     D、void  flower(int x,int s)
  (3)  A、 b=x%100%10  B、b=x%10/10   C、b=x/100%10  D、b=x/10%10
  (4)  A、return x;    B、return 0;   C、return -1;  D、 return 1;

--------------------------------------------------------------------
12 填空:从小到大排序
int main(){
int myarr[10];
         (空1)
        scanf("%d", (空2) )
Bubble(myarr,11);
int i=0;
for(;i<11;i++){
printf("%d:%d\n",i,myarr[i]);
}
return 0;
}
void Bubble(int myarr[],int len){
int length=len;
int i=0;
int j=0;
for(;i<len;i++){
for(;j<length;j++){
if(  (空3) ){
int temp=myarr[j];
        (空4)
myarr[j+1]=temp;
}
}
length--;
j=0;
}
}
--------------------------------------------------------------------
13 填空:对输入一个字符串,统计此字符串中字母,数字,空格,和其它符号的个数
int main()
{
    int letter=0,num=0,space=0,other=0,i;
    char put[1000000];
    gets(put);
    for(i=0;i<1000000;i++)
    {
        if(put[i]=='\n' || put[i]==0)    /* gets 不保存回车,字符串以'\0'结束 */
            break;
        else if( (空1))
            letter++;
        else if( (空2))
            num++;
        else if( (空3))
            space++;
        else
            other++;
    }
    printf("TYPE        No.\n");
    printf("letter      %d\n",letter);
    printf("num         %d\n",num);
    printf("space       %d\n",space);
    printf("other       %d\n",other);
    system("pause");
    return 0;
}

 

 

 

 

 

 

单选题
1、C语言中下列叙述正确的是_D_。
  A:不能使用do-while语句构成的循环
  B:do-while语句构成的循环,必须用break语句才能退出
  C:do-while语句构成的循环,当while语句中的表达式值为非零时结束循环
  D:do-while语句构成的循环,当while语句中的表达式值为零时结束循环
知识点:知识点/循环结构程序设计/WHILE和DO WHILE循环结构

2、下列描述中不正确的是_C_。 
  A:字符型数组中可以存放字符串
  B:可以对字符型数组进行整体输入、输出
  C:可以对整型数组进行整体输入、输出
  D:不能在赋值语句中通过赋值运算符"="对字符型数组进行整体赋值
知识点:知识点/基本语句/数据的输入与输出,输入输出函数的调用

3、以下程序的输出结果是__D__。
main()
{  int   x=10,y=10,i;
   for(i=0;x>8 ;y=++i)
   printf("%d   %d  ",x--,y);
}
  A:10  1  9  2
  B:9  8  7  6
  C:10  9  9  0
  D:10  10  9  1
知识点:知识点/循环结构程序设计/FOR循环结构


4、以下程序的输出结果是___B___。  
main()
{   char  a[10]={'1','2','3','4','5','6','7','8','9',0},*p;
int i ;
i=8;
p=a+i;
printf("%s\n",p-3);
}
  A:6
  B:6789
  C:'6'
  D:789
知识点:知识点/指针/指针数组,指向指针的指针,MAIN函数的命令行参数

5、能正确表示a和b同时为正或同时为负的逻辑表达式是___D___。
  A:(a>=0||b>=0)&&(a<0|| b<0)
  B:(a>=0&&b>=0)&&(a<0&&b<0)
  C:(a+b>0)&&(a+b<=0)
  D:a*b>0
知识点:知识点/基本语句/表达式语句,空语句,复合语句

6、以下程序的输出结果是__A__。
main()
{  int  n=4;
   while(n--)printf("%d   ",--n);
}
  A:2  0
  B:3  1
  C:3  2  1
  D:2  1  0
知识点:知识点/循环结构程序设计/WHILE和DO WHILE循环结构

7、以下程序的输出结果是___D___。
main()  
{  int  k=17;
   printf("%d,%o,%x\n",k,k,k);
}
  A:17,021,0x11
  B:17,17,17
  C:17,0x11,021
  D:17,21,11
知识点:知识点/数据类型及其运算/C的数据类型及其定义方法

8、若有说明:long  *p,a;则不能通过scanf语句正确给输入项读入数据的程序段是___A__。
  A:*p=&a;scanf("%ld",p);
  B:p=(long *)malloc(8);scanf("%ld,p);
  C:scanf("%ld",p=&a);
  D:scanf("%ld",&a);
知识点:知识点/基本语句/数据的输入与输出,输入输出函数的调用

9、以下选项中,能定义s为合法的结构体变量的是__C__。
  A:typedef  struct  abc 
{  double a;
   char b[10];
} s;
  B:struct  
{  double a;
   char  b[10];
}s;
  C:struct  ABC 
{  double a;
   char b[10];

ABC s; 
  D:typedef  ABC
{  double a;
   char b[10]; 

ABC s;

10、请读程序:
    #include <stdio.h>
    main()
    {
       int a, b ;
       for(a = 1 , b = 1 ; a <= 100 ; a++) {
          if(b >= 20)  break ;
          if (b%3 == 1) { b += 3 ; continue ; }
          b -= 5 ;
       }
       printf("%d\n", a) ;
    }
上面程序的输出结果是__B__。
  A:7
  B:8
  C:9
  D:10
知识点:知识点/选择结构程序设计/用SWITCH语句实现多分支选择结构


11、请选出合法的C语言赋值语句__B__。
  A:a=b=58
  B:i++;
  C:a=58,b=58
  D:k=int(a+b);

12、若x和y都是int型变量,x=100、y=200,且有下面的程序片段
      printf("%d",(x,y) );
上面程序片段的输出结果是__A__。
  A:200
  B:100
  C:100   200
  D:输入格式符不够,输出不确定的值

13、若x是整型变量,pb是基类型为整型的指针变量,则正确的赋值表达式是__A__。
  A:pb=&x;
  B:pb=x;
  C:*pb=&x;
  D:*pb=*x

14、设a、b和c都是int型变量,且a=3、b=4、c=5,则下面的表达式中,值为0的表达式是__D__。
  A:'a'&&'b'
  B:a<=b 
  C:a||+c&&b-c 
  D:!((a<b)&&!c||1)

15、有程序如下:
typedef struct link { double score;  struct link  *next; };
void main ( ) {  
link *ps, qs, rs;
ps = ( struct link *) malloc (sizeof (struct link) );
ps->score = 81.5; qs.score = 55.5; rs.score = 68.0;
ps->next = &qs ; qs.next =&rs;
printf ( " %d \n ", ps->score + ps->next->score);
}
上面程序的输出结果是_137_。
--------------------------------------------------------------------
程序设计
1.定义函数double fact( int n) 计算n!的值。 

2.判断数m是否为素数(只能被1和它本身整除的整数)?若是,则输出yes;否则输出no
--------------------------------------------------------------------
3.求出第n项Fibonacci数,并统计前n项之和。Fibonacci序列:1,1,2,3,5,8,13,21,34,55,……。该序列的第一个数和第二个数都是1,从第三个数开始,每个数都是前两个数之和
--------------------------------------------------------------------
4.输入某班级20个学生某课程的考试成绩,要求统计并输出班级总分及大于等于60分的人数。
--------------------------------------------------------------------
5.试编程判断输入的正整数是否既是5又是7的正倍数。若是,则输出yes;否则输出no。
--------------------------------------------------------------------
6.对15个数进行排序,按从小到大的顺序输出
--------------------------------------------------------------------
7.写一个程序,它能够计算并输出杨辉三角形(帕斯卡三角形)前面的 n 行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章