VC代码找错。
题目:编写函数reverse(intnumber),它的功能是将number逆序输出,在主函数钟输入一个整数并调用该函数.我的程序如下:可出现了4个错误,1个警告,看了半...
题目:编写函数reverse(int number),它的功能是将number逆序输出,在主函数钟输入一个整数并调用该函数.
我的程序如下:可出现了4个错误,1个警告,看了半天没看懂啊
--------------------Configuration: xxy5 - Win32 Debug--------------------
Compiling...
5.c
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : warning C4013: 'length' undefined; assuming extern returning int
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2057: expected constant expression
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2466: cannot allocate an array of constant size 0
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2133: 'a' : unknown size
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(8) : error C2059: syntax error : 'type'
Error executing cl.exe.
5.obj - 4 error(s), 1 warning(s)
*******************************************************************
#include<stdio.h>
#include<math.h>
void reverse(int number){
int a[length(number)+1];
int i,j,k;
for(i=1;i<=length(number);i++){
a[i]=int (number/pow(10,(i-1)))%10;
}
for(j=1;j<=length(number);j++){
a[j]=a[length(number)-j+1];
}
for(k=1;k<=length(number);k++){
printf("%d",a[length(number)-k+1]);
}
}
int length(int number){
int i;
for(i=1;;i++){
if (number/pow(10,i)<1) break;
}
return i;
}
void main(){
int i;
printf("请输入一个整数:\n");
scanf("%d",&i);
if (i<0) i=0-i;
reverse(i);
}
高手们99我啊,我搞了好几个小时了都没搞出来 展开
我的程序如下:可出现了4个错误,1个警告,看了半天没看懂啊
--------------------Configuration: xxy5 - Win32 Debug--------------------
Compiling...
5.c
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : warning C4013: 'length' undefined; assuming extern returning int
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2057: expected constant expression
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2466: cannot allocate an array of constant size 0
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(5) : error C2133: 'a' : unknown size
C:\程序\c++\Microsoft Visual Studio\MyProjects\xxy5\5.c(8) : error C2059: syntax error : 'type'
Error executing cl.exe.
5.obj - 4 error(s), 1 warning(s)
*******************************************************************
#include<stdio.h>
#include<math.h>
void reverse(int number){
int a[length(number)+1];
int i,j,k;
for(i=1;i<=length(number);i++){
a[i]=int (number/pow(10,(i-1)))%10;
}
for(j=1;j<=length(number);j++){
a[j]=a[length(number)-j+1];
}
for(k=1;k<=length(number);k++){
printf("%d",a[length(number)-k+1]);
}
}
int length(int number){
int i;
for(i=1;;i++){
if (number/pow(10,i)<1) break;
}
return i;
}
void main(){
int i;
printf("请输入一个整数:\n");
scanf("%d",&i);
if (i<0) i=0-i;
reverse(i);
}
高手们99我啊,我搞了好几个小时了都没搞出来 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询