数组元素的删除.docx
《数组元素的删除.docx》由会员分享,可在线阅读,更多相关《数组元素的删除.docx(15页珍藏版)》请在冰豆网上搜索。
![数组元素的删除.docx](https://file1.bdocx.com/fileroot1/2022-11/16/0ad2d05f-ce2c-4d60-8b7b-c7c84109a423/0ad2d05f-ce2c-4d60-8b7b-c7c84109a4231.gif)
数组元素的删除
试卷编号:
321
所属语言:
计算机基础
试卷方案:
数组元素的删除
试卷总分:
210分
共有题型:
3种
一、程序填空共3题(共计60分)
第1题(20.0分)题号:
24难度:
中第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:
删除一个字符串中的所有数字字符。
-------------------------------------------------------*/
#include"stdio.h"
voiddelnum(chars[])
{
inti,j;
/***********SPACE***********/
for(i=0,j=0;【?
】'\0';i++)
/***********SPACE***********/
if(s[i]<'0'【?
】s[i]>'9')
{
/***********SPACE***********/
【?
】;
j++;
}
s[j]='\0';
}
main()
{
charitem[100];
printf("\ninputastring:
\n");
gets(item);
/***********SPACE***********/
【?
】;
printf("\n%s",item);
}
答案:
=======(答案1)=======
s[i]!
=
=======(答案2)=======
||
=======(答案3)=======
s[j]=s[i]
=======(答案4)=======
delnum(item)
第2题(20.0分)题号:
28难度:
易第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:
输入字符串,再输入一个字符,将字符串中与输入字符相
同的字符删除。
-------------------------------------------------------*/
#include"stdio.h"
voidfun(chara[],charc)
{
inti,j;
/***********SPACE***********/
for(i=j=0;【?
】;i++)
if(a[i]!
=c)a[j++]=a[i];
/***********SPACE***********/
【?
】;
}
main()
{
chara[20],cc;
gets(a);
/***********SPACE***********/
【?
】;
/***********SPACE***********/
【?
】;
puts(a);
}
答案:
=======(答案1)=======
a[i]!
='\0'
=========或=========
a[i]
=========或=========
a[i]!
=NULL
=======(答案2)=======
a[j]='\0'
=========或=========
a[j]=NULL
=========或=========
a[j]=0
=======(答案3)=======
cc=getchar()
=========或=========
scanf("%c",&cc)
=======(答案4)=======
fun(a,cc)
第3题(20.0分)题号:
15难度:
易第1章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
功能:
删除字符串中的指定字符,字符串和要删除的字符均由键盘
输入。
-------------------------------------------------------*/
#include"stdio.h"
main()
{
charstr[80],ch;
inti,k=0;
/***********SPACE***********/
gets(【?
】);
ch=getchar();
/***********SPACE***********/
for(i=0;【?
】;i++)
if(str[i]!
=ch)
{
/***********SPACE***********/
【?
】;
k++;
}
/***********SPACE***********/
【?
】;
puts(str);
}
答案:
=======(答案1)=======
str
=======(答案2)=======
str[i]!
='\0'
=========或=========
str[i]!
=NULL
=========或=========
str[i]!
=0
=========或=========
str[i]
=======(答案3)=======
str[k]=str[i]
=======(答案4)=======
str[k]='\0'
=========或=========
str[k]=NULL
=========或=========
str[k]=0
二、程序改错共2题(共计60分)
第1题(30.0分)题号:
70难度:
中第2章
/*------------------------------------------------------
【程序改错】
--------------------------------------------------------
功能:
删除w所指数组中下标为k的元素中的值。
程序中,调用了
getindex、arrout和arrdel三个函数,getindex用以输入
所删元素的下标,函数中对输入的下标进行检查,若越界,
则要求重新输入,直到正确为止。
arrout用以输出数组中
的数据,arrdel进行所要求的删除操作。
------------------------------------------------------*/
#include"conio.h"
#include"stdio.h"
#defineNUM10
/**********FOUND**********/
arrout(intw,intm)
{
intk;
/**********FOUND**********/
for(k=1;k/**********FOUND**********/
printf("%d"w[k]);
printf("\n");
}
arrdel(intw[],intn,intk)
{
inti;
for(i=k;iw[i]=w[i+1];
n--;
returnn;
}
getindex(intn)
{inti;
do
{printf("\nEntertheindex[0<=i<%d]:
",n);
scanf("%d",&i);
}while(i<0||i>n-1);
returni;
}
main()
{intn,d,a[NUM]={21,22,23,24,25,26,27,28,29,30};
n=NUM;
clrscr();
printf("Outputprimarydata:
\n");arrout(a,n);
d=getindex(n);n=arrdel(a,n,d);
printf("Outputthedataafterdelete:
\n");arrout(a,n);
}
答案:
=======(答案1)=======
arrout(intw[],intm)
=======(答案2)=======
for(k=0;k=======(答案3)=======
printf("%d",w[k]);
第2题(30.0分)题号:
55难度:
中第2章
/*------------------------------------------------------
【程序改错】
--------------------------------------------------------
功能:
删除字符串s中的所有空白字符(包括Tab字符、回车符及
换行符)。
输入字符串时用'#'结束输入。
-----------------------------------------------------*/
#include
#include
#include
fun(charp[])
{
inti,t;charc[80];
/**********FOUND**********/
for(i=1,t=0;p[i];i++)
/**********FOUND**********/
if(!
isspace((p+i)))c[t++]=p[i];
/**********FOUND**********/
c[t]="\\0";
strcpy(p,c);
}
main()
{
charc,s[80];
inti=0;
printf("Inputastring:
");
c=getchar();
while(c!
='#')
{
s[i]=c;i++;c=getchar();
}
s[i]='\0';
fun(s);
puts(s);
}
答案:
=======(答案1)=======
for(i=0,t=0;p[i];i++)
=======(答案2)=======
if(!
isspace(p[i]))c[t++]=p[i];
=======(答案3)=======
c[t]='\0';
三、程序设计共3题(共计90分)
第1题(30.0分)题号:
40难度:
中第2章
/*------------------------------------------------
【程序设计】
--------------------------------------------------
功能:
从字符串中删除指定的字符。
同一字母的大、小写
按不同字符处理。
例如:
若程序执行时输入字符串为:
turbocandborlandc++
从键盘上输入字符:
n,则输出