帮我改改c程序;

[复制链接]
查看11 | 回复1 | 2008-11-9 13:10:42 | 显示全部楼层 |阅读模式
题目:写一个函数,用于十进制转换为八进制;我编了一个程序如下:
#include
void shitoba(int x,char s[])
{int r,k=0;

while(x!=0)
{r=x%8;
s[k]=r+'0';k++;
x=x/8;
}
}
main()
{int a=15; char c[10]={'\0'},i;
shitoba(a,c);
puts(c);
}
将十进制的数15转换成八进制的数是17
输出的结果为 71;怎么样才能使输出的结果为 17。
编译错误信息:
c(15) : error C2143: syntax error : missing ';' before 'type'
c(15) : error C2143: syntax error : missing ';' before 'type'
c(15) : error C2143: syntax error : missing ')' before 'type'
c(15) : error C2143: syntax error : missing ';' before 'type'
.c(15) : error C2065: 'j' : undeclared identifier
c(15) : warning C4552: '>=' : operator has no effect; expected operator with side-effect
c(15) : error C2143: syntax error : missing ';' before ')'
.c(22) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)

回复

使用道具 举报

千问 | 2008-11-9 13:10:42 | 显示全部楼层
#include void shitoba(int x,char s[]) {int r,k=0; while(x!=0) {r=x%8; s[k]=r+'0';k++; x=x/8; } } void main() { int a=1; char c[10]={'\0'}; shitoba(a,c); for (int j=sizeof(c);j>=0;j--) { if (c[j]!=' ') { printf("%c",c[j]); } }}你把编译错误的信息,贴上来...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行