Solution for exercise 1.1-4 in Introduction to Algorithms
来源:互联网 发布:c语言母牛生小牛代码 编辑:程序博客网 时间:2024/05/16 01:50
Consider the problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in an (n + 1)-element array C. State the problem formally and write pseudocode for adding the two integers.
/*
* Adding two n-bit binary integers, stored in two n-element arrays A and B.
* The sum of the two integers should be stored in binary form in an
* (n+1)-element array C.
*/
int* addIntegers(int A[], int B[], int n) {
int carry = 0;
int* C = new int[n + 1];
for (int i = 0; i < n; i++) {
int sum = A[i] + B[i] + carry;
carry = sum / 2;
C[i] = sum % 2;
}
C[n] = carry;
return C;
}
- Solution for exercise 1.1-4 in Introduction to Algorithms
- Solution for exercise 1.2-1 in Introduction to Algorithms
- Solution for exercise 1.2-3 in Introduction to Algorithms
- Solution for exercise 1.3-5 in Introduction to Algorithms
- Solution for exercise 1.3-7 in Introduction to Algorithms
- Solution for Introduction to Algorithms (3rd Edition) Exercise 26.4-2
- Solution of Introduction to Algorithms
- About Introduction to Algorithms
- Introduction to Algorithms
- Introduction to Algorithms
- BUBBLESORT: INTRODUCTION TO ALGORITHMS
- Introduction to Algorithms
- An Introduction to Genetic Algorithms In Java @ JDJ
- Quick Introduction to Boosting Algorithms in Machine Learning
- introduction to algorithms 菜鸟笔记 sort algorithms
- Introduction to String Searching Algorithms
- 《Introduction to Algorithms》Second Edition
- Book "Introduction to Algorithms" Got
- 使用VB.NET线程访问数据库
- 如何辨别网络入侵检测系统(IDS)的性能
- 如何在窗体以外的地方绘制图像
- 网络防火墙防范溢出策略
- Asp基础教程(上)
- Solution for exercise 1.1-4 in Introduction to Algorithms
- Asp基础教程(下)
- ASP 中20个技巧介绍
- 覆盖地址HOOK API
- ASP提速技巧五则
- 血泪程序员
- 使用SoftICE调试程序入门
- ASP 验证码的程序及原理
- 在ASP中连接数据库(连接字符串)