按给定函数原型编程检查一个字符串是否全由数字组成。 int IsAllDigit(char p[]);/*若全由数字组成,则函数返回1,否则返回0*/ 在主函数中,从键盘输入一个字符串(假设字符串的最大长度为20个字符),调用函数IsAllDigit(),检查该字符串是否全由数字组成,然后在主函数中根据函数IsAllDigit()的返回值输出相应的提示信息。 程序的第1次运行结果: Please input a string: help456↙ The string is not digit string. 程序的第2次运行结果: Please input a string: 20150216↙ The string is digit string. 在空白处填写适当的表达式或语句,使程序完整并符合题目要求。 #include <stdio.h> int IsAllDigit(char p[]); int main() { char a[80]; printf("Please input a string:\n"); gets(a); if (IsAllDigit(a)) printf("The string is digit string."); else printf("The string is not digit string."); return 0; } int IsAllDigit(char p[]) { int flag = 1, i; for (i = 0; ___________; i++) { if (___________________) { flag = 0; _________; } } return flag; }
A、第17行: p[i] != '\0' 第19行: p[i] < '0' || p[i] > '9' 第22行: break
B、第17行: p[i] = '\0' 第19行: p[i] < '0' && p[i] > '9' 第22行: continue
C、第17行: p[i] == '\0' 第19行: p[i] < 0 || p[i] > 9 第22行: break
D、第17行: p[i] != '\n' 第19行: p[i] < 0 && p[i] > 9 第22行: continue
第2题
第4题
第5题
第6题
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include<stdlib.h>
include<string.h>
define N 8
int xx[N];
int fun(char *str,int x,int y)
{
int sum;
int i=0;
char *p=str;
for(i=0; i<N; i++)
xx[i]=0;
sum=*p-'0';
p++;
while (*p)
{
sum=【 】;
p++;
}
i=0;
while(sum!=0)
{
xx[i]=【 】;
【 】;
i++;
}
return i;
}
main ()
{
char str[6];
int i;
int n;
int x;
int y;
printf("Enter a string made up of '0' to
'9' digits character:");
gets(str);
if(strlen (str) >5)
{
printf("Error:string too longer!,
please input again!\n\n");
exit(0);
}
for(i=0;str[i];i++)
if(str[i]<'0'||str[i]>'9')
{
printf("Error:%c not is '0' to
'9' digits character!\n\n",
str[i]);
exit(0);
}
printf("The original string: ");
puts(str);
printf("\nINPUT x= ");
scanf("%d",&x);
printf("\nINPUT y= ");
scanf("%d",&y);
n=fun(str,x,y);
printf("\n%s is convered to",str);
for (i=n-1; i>=0; i--)
printf("%d",xx[i]);
}
第8题
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,敢不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
int fun(char t[])
{
char c;
int i,j;
for(i=0;i<strlen(t)-1;i++)
for(j=i+1;i<strlen(t);j++)
if(t[i]<t[j])
{
c=t[j];
/*************found**************/
t[i]=t[i++];
t[i]=c;
}
}
main()
{
char s[81];
clrscr();
printf("\nPlease enter a character
string:");
gets(s);
printf("\n\nBefore sorting:\n%S",s);
fun(s);
printf("\nAfter sorting decendingly:\n
%s",s);
}
第10题
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!