c语言输入p 保证p>100,C语言程序设计100题(续).doc

功能:将一个字符串中的前N个字符复制到一个字符数组中去,不许使用strcpy函数。

#include

main ( )

{

char str1[80],str2[80];

int i,n;

/***********SPACE***********/

gets(【?】); scanf("%d",&n);

/***********SPACE***********/

for (i=0; 【?】 ;i++) /***********SPACE***********/

/***********SPACE***********/

【?】;

printf("%s\n",str2);

}

答案:

=======(答案1)=======

str1

=======(答案2)=======

i

=========或=========

n>i

=========或=========

i<=n-1

=========或=========

n-1>=i

=======(答案3)=======

str2[i]=str1[i]

=========或=========

*(str2+i)=*(str1+i)

=========或=========

*(str2+i)=str1[i]

=========或=========

str2[i]=*(str1+i)

=======(答案4)=======

str2[n]='\0'

=========或=========

str2[i]='\0'

=========或=========

str2[n]=0

=========或=========

str2[i]=0

=========或=========

*(str2+n)='\0'

=========或=========

*(str2+i)='\0'

=========或=========

*(str+n)=0

=========或=========

*(str2+i)=0

二、程序改错 共1题 (共计30分)

功能:请输入星期几的第一个字母来判断一下是星期几,如果第一

个字母一样,则继续判断第二个字母。

#include "conio.h"

#include

void main(){

char letter;

printf("please input the first letter of someday\n");

/**********FOUND**********/

while ((letter=getch())='Y')letter=getch()!=Y

{

switch (letter)

{

case 'S':

printf("please input second letter\n");

if((letter=getch())=='a')

printf("saturday\n");

else if ((letter=getch())=='u')

printf("sunday\n");

else printf("data error\n");

break;

case 'F':

printf("friday\n");

break;

case 'M':

printf("monday\n");

break;

case 'T':

printf("please input second letter\n");

if((letter=getch())!='u')getch()=’u’

printf("tuesday\n");

else if ((letter=getch())=='h')

printf("thursday\n");

else

printf("data error\n");

/**********FOUND****

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值