填空题:字符串str由数字字符组成(长度不超过5个字符),可看做任意进制的数,请补充函数proc(),该函数的功能是:把str字

  • 题目分类:C语言
  • 题目类型:填空题
  • 查看权限:VIP
题目内容:
字符串str由数字字符组成(长度不超过5个字符),可看做任意进制的数,请补充函数proc(),该函数的功能是:把str字符串从二进制转换卜进制的数,结果保存在数组。x 中,由函数返回转换后数组xx的实际长度。其中。表示str 原来的进制,y表示要转换成的进制。例如,输入str=”1011”,x=2,y=10,结果输出:11。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#inelude<string.h>
#define M 8
int xx[M];
int proc(char*str,int x,int y)
{
int sum;
int i=0:
char*p=str;
for(i=0;i<M;i++)
xx[i]=0:
sum= 【1】
p++;
while(*p)
{
sum=sum*x+*p-'0';
P++:
}
i=0;
while(sum!=O)
{
xx[i]=【2】
【3】
i++:
}
return i;
}
void 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 a
gain!\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=proc(str.x,y);
printf("\n%s is convered to",str);
for(i=n-l:i>=0;i--)
printf("%d\n",xx[i]/n);
}
参考答案:
答案解析:

下列给定程序中,函数proc()的功能是:对M名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学

下列给定程序中,函数proc()的功能是:对M名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,

查看答案

设有定义:char p[]={'1','2','3'),*q=p;,以下不能计算出一个char型数据所占字节数的表达式是

设有定义:char p[]={'1','2','3'),*q=p;,以下不能计算出一个char型数据所占字节数的表达式是( )。A.sizeof(p) B.s

查看答案

已有定义:char c;,程序前面已在命令行中包含ctype.h文件,不能用于判断c中的字符是否为大写字堪的表达式是(

已有定义:char c;,程序前面已在命令行中包含ctype.h文件,不能用于判断c中的字符是否为大写字堪的表达式是( )。A.isupper(c) B.'A

查看答案

下列链表中,其逻辑结构属于非线性结构的是(  )。

下列链表中,其逻辑结构属于非线性结构的是(  )。 A.二叉链表 B.循环链表 C.双向链表 D.带链的栈

查看答案

Which of the following is NOT true?

Which of the following is NOT true?A.People call visit Ellis Isalnd free of ch

查看答案