当前位置: 代码迷 >> C语言 >> [求助]又有问题了
  详细解决方案

[求助]又有问题了

热度:348   发布时间:2007-05-30 14:39:08.0
[求助]又有问题了

输入一个三位整数,依输出该整数的正(负)号和百位、十位、个位数字。下面是我写的,运行后百位上的数字不输出,大家帮下忙看看是什么问题。

#include "stdio.h"
#include "math.h"
main()
{
char c1,c2,c3,c4;
int x;
scanf("%d",&x);
c1=(x>=0?'+':'-');
x=abs(x);
c4=x%10+48;
x=x/10;
c3=x%10+48;
c2=x/10;
printf("\n%c\n%c\n%c\n%c",c1,c2,c3,c4);
}

[此贴子已经被作者于2007-5-30 16:30:59编辑过]

搜索更多相关的解决方案: include  color  

----------------解决方案--------------------------------------------------------
#include "stdio.h"
#include "math.h"
main()
{
char c1,c2,c3,c4;
int x;
scanf("%d",&x);
c1=(x>=0?'+':'-');
x=abs(x);
c4=x%10+48;
x=x/10;
c3=x%10+48;
c2=x/10+48;

printf("\n%c\n%c\n%c\n%c",c1,c2,c3,c4);
}这样就可以了
你少了一个加48
也可以用别的方法的用这种方法我以前也没有用过
----------------解决方案--------------------------------------------------------

又是一个低级错误。我刚开始学习C语言,经常是漏这漏那的,唉!


----------------解决方案--------------------------------------------------------
哈哈,以后注意点
----------------解决方案--------------------------------------------------------
我把上面的程序改了,TC提示说有错误
各位学长再给帮下,看下错在哪里。先在这谢过了。

#include "stdio.h"
#include "math.h"
main()
{
char c1,c2,c3,c4;
int x;
scanf("%d",&x);
if
{
x>999||x<-999;
printf("you are wrong \n");
}

else
{
c1=(x>=0?'+':'-');
x=abs(x);
c4=x%10+48;
x=x/10;
c3=x%10+48;
c2=x/10+48;
printf("\n%c\n%c\n%c\n%c",c1,c2,c3,c4);
}
}

----------------解决方案--------------------------------------------------------
以下是引用蓝一在2007-5-30 14:39:08的发言:

输入一个三位整数,依输出该整数的正(负)号和百位、十位、个位数字。下面是我写的,运行后百位上的数字不输出,大家帮下忙看看是什么问题。

#include "stdio.h"
#include "math.h"
main()
{
char c1,c2,c3,c4;
int x;
scanf("%d",&x);
c1=(x>=0?'+':'-');
x=abs(x);我是更新的新手, x=abs(x)是把他转成字符的意思吗?不然是什么意思呢?我不懂,告诉我哦,谢谢拉
c4=x%10+48;
x=x/10;
c3=x%10+48;
c2=x/10;
printf("\n%c\n%c\n%c\n%c",c1,c2,c3,c4);
}


----------------解决方案--------------------------------------------------------
你学的c语言书后有没有附录呀
----------------解决方案--------------------------------------------------------

回复:(夜中梦)以下是引用蓝一在2007-5-30 14:39:08...
函数名: abs
功 能: 求整数的绝对值
用 法: int abs(int i);
程序例:
#include <stdio.h>
#include <math.h>
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}

----------------解决方案--------------------------------------------------------

学长给看下我改成if else 语句后怎么不行了。没觉得用错什么啊。

[此贴子已经被作者于2007-5-30 15:48:20编辑过]


----------------解决方案--------------------------------------------------------
解决了

#include "stdio.h"
#include "math.h"
main()
{
char c1,c2,c3,c4;
int x;
scanf("%d",&x);
if(x>999||x<-999)/*偶把if else的格式都给忘了*/
{
printf("you are wrong \n");
}

else
{
c1=(x>=0?'+':'-');
x=abs(x);
c4=x%10+48;
x=x/10;
c3=x%10+48;
c2=x/10+48;
printf("\n%c\n%c\n%c\n%c",c1,c2,c3,c4);
}
}

[此贴子已经被作者于2007-5-30 15:54:57编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案