扭转数字的数字 [英] to reverse the digits of a number

查看:102
本文介绍了扭转数字的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我以下代码有什么问题吗?

给出了

a简单的输入值,如:10001,10032,10432,一切似乎都是

工作得很好,但在给出输入值如

43211它没有用,有些价值的'' - ''标志在它之前


显示。

i hve。尝试使用long int也是如此。


| void main()

| {

| clrscr();

| int a,i,d,sum = 10000,sum1 = 0;

| printf(输入您选择的五位数:);

| scanf("%d"& a);

|

| for(i = 0; i< = 4; i ++)

| {

| d = a%10;

| a = a / 10;

| d = d *总和;

| sum1 = sum1 + d;

| sum = sum / 10;

| printf("%d \ nn",sum1);

| }

|的printf(QUOT;%d" \\\
",SUM1);

|的getch();

| }

解决方案

dipti写道:

请你们告诉我什么是错的使用以下代码
| void main()
^^^^

已经死了。 main的返回类型为int | {
| clrscr();
^^^^^^

再次死亡。不仅clrscr()不是标准函数,那么

在代码中没有声明或定义,甚至没有包含

非标准头文件。 | int a,i,d,sum = 10000,sum1 = 0;
| printf(输入你选择的五位数:);
^^^^^^

再次死亡。没有声明,甚至没有包含< stdio.h> |的scanf(QUOT;%d",&安培;一个);
^^^^^

再次死亡。没有声明,甚至没有包含< stdio.h>

此外,提示后面既没有''\ n''也没有打电话给

''fflush(stdout);''因此没有理由认为提示出现了。 |
| for(i = 0; i <= 4; i ++)
| {
| d = a%10;
| A = A / 10;
a / = 10;如果没有对|的两个引用,也会这样做d = d *总和;
| sum1 = sum1 + d;
|总和=总和/ 10;
这看起来不连贯。

看起来你真的想要像

这样的代码[而不是整个(i ...循环)

if(a< 0){

putchar('' - '');

a = -a;

}

sum = 0;

而(a){

sum * = 10;

sum + = a %10;

a / = 10;

printf("%d \ nn",sum);

}
| printf("%d \ n",sum1);
|}
| printf("%d" \ n",sum1);
这是不必要的。 | getch();
再次死亡。不仅getch()不是标准函数,还有

代码中没有声明或定义,甚至没有包含

a非标准标题。


如果你不使用C99编译器,你需要(并且应该使用C99编译器,甚至是

) )

返回0;

|}





dipti写道:

请你们告诉我以下代码有什么问题
就像给出一个简单的输入值一样:10001,10032,10432,一切似乎都很好
工作正常但是在给出一个输入值,比如
43211它不起作用,前面带有'' - ''符号的一些值得到
我只是尝试了这个特定的输入,它给了我正确的输出
(使用VS 2005),您是否有机会使用旧的16位编译器?

显示。
我好。尝试使用long int也是这样。



它没有什么区别,它们是32位
编译器的32位大小...


Abdo Haji-Ali

程序员

In | Framez




dipti写道:

请你们告诉我以下代码有什么问题
给出一个简单的输入值,如:10001,10032,10432,一切似乎都工作正常,但在给出输入值如
43211它不起作用,有些价值' ' - ''之前的标志是获得
我只是尝试了这个特定的输入并且它给了我正确的结果

(使用VS 2005),你是否有机会使用16位编译器?

显示。
我好。尝试使用long int也是这样。



32位编译器的32位大小相同......


[code]


Abdo Haji-Ali

程序员

In | Framez


Hi, Can u guys please tell me what''s wrong with the following code
as on giving
a simple input value like: 10001, 10032, 10432, everything seems to be
working fine but on giving a input value like
43211 it''s not working,some value with ''-'' sign preceding it is getting

display.
i hve. tried this using long int also.

| void main()
| {
| clrscr();
| int a,i,d,sum=10000,sum1=0;
| printf("Enter A Five Digit No.of Your Choice:");
| scanf("%d",&a);
|
| for(i=0;i<=4;i++)
| {
| d=a%10;
| a=a/10;
| d=d*sum;
| sum1=sum1+d;
| sum=sum/10;
| printf("%d\n",sum1);
| }
| printf("%d"\n",sum1);
| getch();
| }

解决方案

dipti wrote:

Hi, Can u guys please tell me what''s wrong with the following code | void main() ^^^^
dead already. main has a return type of int | {
| clrscr(); ^^^^^^
dead again. Not only is clrscr() not a standard function, there
is no declaration or definition in your code, not even the inclusion of
a non-standard header. | int a,i,d,sum=10000,sum1=0;
| printf("Enter A Five Digit No.of Your Choice:"); ^^^^^^
dead again. No declaration, not even the inclusion of <stdio.h> | scanf("%d",&a); ^^^^^
dead again. No declaration, not even the inclusion of <stdio.h>
In addition, the prompt is followed by neither a ''\n'' nor call to
''fflush(stdout);'' so there is no reason to suppose the prompt appears. |
| for(i=0;i<=4;i++)
| {
| d=a%10;
| a=a/10; a /= 10; would do as well, without the two references to a | d=d*sum;
| sum1=sum1+d;
| sum=sum/10; This looks incoherent.
It would seem that you actually want code like
[instead of the whole for(i... loop]
if (a < 0) {
putchar(''-'');
a = -a;
}
sum = 0;
while(a) {
sum *= 10;
sum += a%10;
a /= 10;
printf("%d\n",sum);
}
| printf("%d\n",sum1);
| }
| printf("%d"\n",sum1); And this is unneeded. | getch(); dead again. Not only is getch() not a standard function, there
is no declaration or definition in your code, not even the inclusion of
a non-standard header.

If you are not using a C99 compiler, you need (and should have, even
using a C99 compiler)
return 0;
| }




dipti wrote:

Hi, Can u guys please tell me what''s wrong with the following code
as on giving
a simple input value like: 10001, 10032, 10432, everything seems to be
working fine but on giving a input value like
43211 it''s not working,some value with ''-'' sign preceding it is getting I just tried this specific input and it gave me the correct ouput
(using VS 2005), are you by any chance using an old 16-bit compiler?
display.
i hve. tried this using long int also.


It won''t make a difference, they are the both 32-bit size on a 32-bit
compiler...

Abdo Haji-Ali
Programmer
In|Framez



dipti wrote:

Hi, Can u guys please tell me what''s wrong with the following code
as on giving
a simple input value like: 10001, 10032, 10432, everything seems to be
working fine but on giving a input value like
43211 it''s not working,some value with ''-'' sign preceding it is getting I just tried this specifc input and it gave me the correct results
(using VS 2005), are you by any chance using a 16-bit compiler?
display.
i hve. tried this using long int also.


It''s the same both are 32-bit size on a 32-bit compiler...

[code]

Abdo Haji-Ali
Programmer
In|Framez


这篇关于扭转数字的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆