- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是C语言的初学者,我必须做一个函数来对两个数组进行加、减、乘,并将其放入另一个数组中。在add函数中如果发生溢出则必须返回false。在 sub 函数中,如果 n1 小于 n2,则必须返回 false。在乘法函数中,如果发生溢出则必须返回 false。我有以下基数,首先是 0 的完整数组,然后最小权重的数量位于索引 0 中。例如,如果我输入 234,则 BigInt 将是索引 79 0000...00234 索引 0
#define MaxDigits 80
typedef unsigned char byte;
typedef byte BigInt [MaxDigits];
这是我必须添加的:
bool addBigInt( const BigInt n1, const BigInt n2, BigInt res ){
int carry=0;
for(int i=0;i<80;++i){
if(n1[i]+n2[i]>9){
carry=res[i]%10;
}
res[i]=n1[i]+n2[i]+carry;
}
if((n1[79]+n2[79]>9) ||(n1[78]+n2[78]>10 && n1[79]+n2[79]>8) ){
return false;
}
else{
return true;
}
}
子一:
bool subBigInt( const BigInt n1, const BigInt n2, BigInt res ) {
for(int i=0;i<80;++i){
res[i]=n1[i]-n2[i];
}
for(int i=80;i>0;i--){
if(n1[i]-n2[i]<0){
return false;
}
}
return true;
}
我真的不知道如何使用 bool 值,如果你能帮助我,我将非常感激。谢谢你
最佳答案
对于添加,可能是这样的
bool addBigInt( const BigInt n1, const BigInt n2, BigInt res ) {
int i, sum, carry = 0;
for(i=0; i<MaxDigits; i++) {
sum = n1[i] + n2[i] + carry;
res[i] = sum % 10;
carry = sum / 10;
}
return carry == 0;
}
关于c - 数组相加、相减、相乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058424/
这个问题已经有答案了: Diff of two Dataframes (8 个回答) 已关闭 4 年前。 我有 2 个数据框(df_a 和 df_b),有 2 列:“动物”和“名称”。 在更大的数据框
如果我得到以下数字字符串,是否可以使用 LINQ 查询将这些数字一起加/减? string numbers = "1 + 1, 2 - 1, 3 + 3"; 所以我最终会得到这样的东西: 字符串数字
具有以下对象列表: public class Example { public string Local { get; set; } public string Type { get;
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
#include #include float sum (float *A, int len) // sum of table of floats { float ss = 0.0;
我正在阅读这篇博文:https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/ 我很困惑: size_t len = end
我正在阅读这篇博文:https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/ 我很困惑: size_t len = end
这个问题已经有答案了: Pointer Arithmetic In C (2 个回答) Pointer subtraction confusion (8 个回答) 已关闭 4 年前。 int vect
我知道这可能是个愚蠢的问题,但我遇到了一些麻烦,我很惭愧,但我真的不知道如何做到。我想加减两个以整数形式给出的“小时”。 #include #include #include using nam
大家好 StackOverflow.. 这个网站相当新,但我得到了很好的反馈!所以首先要感谢大家! 我想做的是类似于wonga的事情 https://www.wonga.com/ 但是随着值的协同工作
我是一名优秀的程序员,十分优秀!