在C中添加4个20位数字 [英] Add 4 20 digit numbers in C

查看:80
本文介绍了在C中添加4个20位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




任何人都可以提出如何在ANSI C中添加4个20位数字的想法和

将结果传回给调用程序COBOL?我们能够在没有任何问题的情况下将
加起来达到15位数,但是一旦我们超过15位,我们就开始面临

问题了。


谢谢,

Venkat

Hi,

Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and
pass the result back to a calling program in COBOL? We were able to
add up to 15 digit numbers without any problems, but we started facing
issues once we go above 15 digits.

Thanks,
Venkat

推荐答案

2007年11月7日星期三20:43: 47 -0800,thehobbit< ve ********** @ gmail.com>

在comp.lang.c中写道:
On Wed, 07 Nov 2007 20:43:47 -0800, thehobbit <ve**********@gmail.com>
wrote in comp.lang.c:




任何人都可以提出如何在ANSI C中添加4个20位数字的想法和

将结果传回给调用COBOL中的程序?我们能够将b $ b加起来没有任何问题,但是一旦我们超过15位,我们就开始面临

问题了。
Hi,

Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and
pass the result back to a calling program in COBOL? We were able to
add up to 15 digit numbers without any problems, but we started facing
issues once we go above 15 digits.



ANSI C或ISO C,或者只是普通标准C,没有定义与
COBOL或任何其他语言的链接。所以没有办法在ANSI

C中执行此操作。


另一方面,您可能遇到数字精度问题

你正在使用的C实现,无论你如何在C程序中获得

值。


但是你避风港没有提供足够的信息。这些数字是什么类型?
?整数,浮点数,什么?他们在C中定义了什么数据类型




你还没有告诉我们什么是问题你认为你有。


你使用的C数据类型有多少位数?


如果这是一个整数类型,您可以查看

< limits.h中的type_MAX宏来告诉您该类型可以处理的值的范围

是。


如果您使用其中一种浮点类型,请查看

< float.h>中的type_DIG。


-

Jack Klein

主页: http:// JK- Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang .learn.c-c ++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ- acllc.html

ANSI C, or ISO C, or just plain standard C, does not define linkage to
COBOL or any other language. So there is no way to do this in "ANSI
C".

On the other hand, you may have an issue with numeric precision in the
C implementation you are using, regardless of how you are getting the
values into the C program.

But you haven''t provided nearly enough information. What types are
these numbers? Integers, floating point, what? What data type are
they defined as in C?

And you haven''t told us what "problems" you think you are having.

How many digits does the C data type you are using have?

If this is an integer type, you can look at the type_MAX macro in
<limits.hto tell you what the range of values the type can handle
is.

If you are using one of the floating point types, look at type_DIG in
<float.h>.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html




感谢您详细介绍...实际上是C中的nincompoop ...

更多的是COBOL程序员...实际上我们要做的是添加

4 20位整数并将总和返还给COBOL程序。这个
是因为COBOL有18位数的限制。当我们添加了15 4

数字整数时,我们得到了预期的总和,但是当我们

开始添加16个4位整数时,那么总和都是错误的......

我们编写的代码如下;如果您有任何建议,请告诉我们。


#include< stdio.h>

#include < stdlib.h>

#include< string.h>

/ *

*添加4个整数的函数

* /


void ccadd(char * inp1,char * inp2,char * inp3,char * inp4,char * out)

{

long long int_inp1,int_inp2,int_inp3,int_inp4,int_out;

int_inp1 = atoi(inp1);

int_inp2 = atoi(inp2);

int_inp3 = atoi(inp3);

int_inp4 = atoi(inp4);


int_out = int_inp1 + int_inp2 + int_inp3 + int_inp4;

sprintf(out,"%lf",int_out);

}

11月7日晚9点20分,杰克Klein< jackkl ... @ spamcop.netwrote:

Thank you for the details jack... actually am a nincompoop in C...
more of a COBOL programmer... actually what we are trying to do is add
4 20 digit integers and return the sum back to the COBOL program. This
is because COBOL has a limitation of 18 digits. When we added 15 4
digit integer numbers we got the expected sum, however the moment we
started adding 16 4 digit integers then the sum was all wrong... the
code we kind of wrote is as follows; Please let us know if you have
any suggestions...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Function to add 4 integers
*/

void ccadd(char *inp1,char *inp2,char *inp3,char *inp4,char *out)
{
long long int_inp1,int_inp2,int_inp3,int_inp4,int_out;
int_inp1 = atoi(inp1);
int_inp2 = atoi(inp2);
int_inp3 = atoi(inp3);
int_inp4 = atoi(inp4);

int_out = int_inp1 + int_inp2 + int_inp3 + int_inp4;
sprintf(out,"%lf",int_out);
}
On Nov 7, 9:20 pm, Jack Klein <jackkl...@spamcop.netwrote:

2007年11月7日星期三20:43:47 -0800,thehobbit< venkat.na .. 。@ gmail.com>

在comp.lang.c中写道:
On Wed, 07 Nov 2007 20:43:47 -0800, thehobbit <venkat.na...@gmail.com>
wrote in comp.lang.c:


Hi,


任何人都可以提出如何在ANSI C中添加4个20位数字的想法和

将结果传递回COBOL中的调用程序?我们能够将b $ b加起来没有任何问题,但是一旦我们超过15位,我们就开始面临

问题了。
Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and
pass the result back to a calling program in COBOL? We were able to
add up to 15 digit numbers without any problems, but we started facing
issues once we go above 15 digits.



ANSI C或ISO C,或者只是普通标准C,没有定义与
COBOL或任何其他语言的链接。所以没有办法在ANSI

C中执行此操作。


另一方面,您可能遇到数字精度问题

你正在使用的C实现,无论你如何在C程序中获得

值。


但是你避风港没有提供足够的信息。这些数字是什么类型?
?整数,浮点数,什么?他们在C中定义了什么数据类型




你还没有告诉我们什么是问题你认为你有。


你使用的C数据类型有多少位数?


如果这是一个整数类型,您可以查看

< limits.h中的type_MAX宏来告诉您该类型可以处理的值的范围

是。


如果您使用其中一种浮点类型,请查看

< float.h>中的type_DIG。


-

Jack Klein

主页: http:// JK- Technology.Com

常见问题解答

comp.lang.chttp://c-faq.com/

comp.lang .c ++ http://www.parashift.com/c++-faq-lite /

alt.comp.lang.learn.c-c ++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html


thehobbit wr ote:


将来,请不要发帖。
thehobbit wrote:

In future, please don''t top post.

感谢您的详细信息杰克...实际上我是C中的一个nincompoop ...

更多的是COBOL程序员...实际上我们要做的是添加

4 20位整数并返回总和回到COBOL程序。这个
是因为COBOL有18位数的限制。当我们添加了15 4

数字整数时,我们得到了预期的总和,但是当我们

开始添加16个4位整数时,那么总和都是错误的......

我们编写的代码如下;如果您有任何建议,请告诉我们。


#include< stdio.h>

#include < stdlib.h>

#include< string.h>

/ *

*添加4个整数的函数

* /


void ccadd(char * inp1,char * inp2,char * inp3,char * inp4,char * out)
Thank you for the details jack... actually am a nincompoop in C...
more of a COBOL programmer... actually what we are trying to do is add
4 20 digit integers and return the sum back to the COBOL program. This
is because COBOL has a limitation of 18 digits. When we added 15 4
digit integer numbers we got the expected sum, however the moment we
started adding 16 4 digit integers then the sum was all wrong... the
code we kind of wrote is as follows; Please let us know if you have
any suggestions...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Function to add 4 integers
*/

void ccadd(char *inp1,char *inp2,char *inp3,char *inp4,char *out)



输入const char *。

Make the inputs const char*.


{

long long int_inp1,int_inp2,int_inp3,int_inp4,int_out ;

int_inp1 = atoi(inp1);
{
long long int_inp1,int_inp2,int_inp3,int_inp4,int_out;
int_inp1 = atoi(inp1);



不要使用atoi将C字符串转换为long long,使用strtoll,或者如果

你100%确定C字符串代表有效数字,环礁。


-

Ian Collins。

Don''t use atoi to convert a C string to long long, use strtoll, or if
you are 100% sure the C strings represent valid numbers, atoll.

--
Ian Collins.


这篇关于在C中添加4个20位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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