1. 程式人生 > >程式設計基礎小測試

程式設計基礎小測試

小測試
1 . 設y是int型變數,請寫出判斷y為奇數的關係表達if(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語言中的基本資料型別包括( int )(char  )(float  )。
--------------------------------------------------------------------
 7. 若有float f1=2.7,f2=13.5; float *fp=&f1;*fp/=4; fp=&f2;,則*fp的值是(  13.5)
--------------------------------------------------------------------
8. 假設已經定義一個字元陣列arr[10],賦給他的初值(xiaowang)的語句是(char 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 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    A ;
    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  D    
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 m=0;m<10;m++)
        scanf("%d", (空2)&myarr[m] );
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( put[i]>=’A’&&put[i]<=’z’(空1))
            letter++;
        else if(put[i]>=0&&put[i]<=9 (空2))
            num++;
        else if( put[i]==’ ’(空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;
}