您的位置:首页 > 其它

总结:程序设计基础 小测试

2013-06-21 00:42 246 查看
小测试

1 . 设y是int型变量,请写出判断y为奇数的关系表达__if(y%2==1)____

--------------------------------------------------------------------

2. 以下程序运行后的输出结果是__98____

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. 假设已经定义一个字符数组arr[10],赋给他的初值(xiaowang)的语句是(for(int i=0;i<9;i++){scanf("%d",&arr[i]);})

--------------------------------------------------------------------

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  A     ))==NULL)

    {    printf("Open file is fail\n");

         exit(0);

    }

    printf("输入n:");

    scanf("%d",&n);

    printf("输入实数: ");

    scanf("%lf",&x);

        2     B

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

      scanf("%lf",&x);

      if(a<x) a=x;

      if (b>x)     3     B

    }

         4  B   ;

    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  C   ) 

printf("水仙花数:%d\n",m);    

}

     2     C

{  int a,b,c,s;

    a=x%10;
    3    B
c=x/100;
s=a*a*a+b*b*b+c*c*c;
if (s==x)        4  D   ;   

   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: for(int n=0;n<10;n++))

        scanf("%d", (空2:myarr
) )
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:myarr[j]>myarr[j+1]) ){
int temp=myarr[j];
        (空4: myarr[j]=myarr[j+1];)
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: put[i]>='A'&&put[i]<='Z'||put[i]>='a'&&put[i]<='z'))letter++;

        else if( (空2: put[i]>='1'&&put[i]<='9'))

            num++;

        else if( (空3: put[i]=' '))

            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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: