剑指Offer47 不用加减乘除做加法
/*************************************************************************
> File Name: 47_AddTwoNumbers.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: 2016年09月04日 星期日 21时33分07秒
************************************************************************/ #include <stdio.h> // 移位求两数相加
int ADD(int num1, int num2)
{
int sum, carry;
if (num1 == )
return num2;
if (num2 == )
return num1; while (num2 != )
{
sum = num1 ^ num2;
carry = (num1 & num2) << ; num1 = sum;
num2 = carry;
}
return sum;
} int main()
{
int num1 = ;
int num2 = ; int sum = ADD(num1, num2);
printf("sum is %d\n", sum);
return ;
}
剑指Offer47 不用加减乘除做加法的更多相关文章
- 剑指Offer——不用加减乘除做加法
题目描述: 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 分析: "^"是不带进位的加法. "&"可以得到所有进位位组 ...
- 剑指offer--12.不用加减乘除做加法
位运算,好久没用了 &:都为1,结果为1 ^:相同为0,不同为1 |:有1,结果为1 <<:左移 ----------------------------------------- ...
- 剑指Offer-不用加减乘除做加法
package Other; /** * 不用加减乘除做加法 * 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. * 思路:位运算 * 1.两个数异或:相当于每一位相加 ...
- 剑指Offer - 九度1507 - 不用加减乘除做加法
剑指Offer - 九度1507 - 不用加减乘除做加法2013-11-29 20:00 题目描述: 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 输入: 输入可能包 ...
- 剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers)
剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers) https://leetcode.com/problems/sum-of-two-in ...
- 剑指 Offer 65. 不用加减乘除做加法 + 位运算
剑指 Offer 65. 不用加减乘除做加法 Offer_65 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author WaleGa ...
- 【剑指offer】65. 不用加减乘除做加法
剑指 Offer 65. 不用加减乘除做加法 知识点:数学:位运算 题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用 "+"."-"."* ...
- 【剑指Offer】不用加减乘除做加法 解题报告(Java)
[剑指Offer]不用加减乘除做加法 解题报告(Java) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews 题 ...
- 剑指offer(48)不用加减乘除做加法
题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 题目分析 不用加减乘除做加法,我第一时间想到的就是用位运算,毕竟计算机是二进制的,所有的操作都是以位运算为基础 ...
随机推荐
- WCF再学习小结
http://www.cnblogs.com/jillzhang/archive/2010/04/04/1704388.html http://leelei.blog.51cto.com/856755 ...
- 新浪微博SSO登陆机制
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- Animated Scroll to Top
Due to a number of requests, I'm writing a detail tutorial on how to create an animated scroll to to ...
- CodeForces 176B Word Cut dp
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...
- hdu 5591 ZYB's Game 博弈论
ZYB's Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=55 ...
- JavaScript Modules
One of the first challenges developers new to JavaScript who are building large applications will ha ...
- [AnuglarJS] TweenMax with ngAnimate
Also read: http://www.cnblogs.com/Answer1215/p/3941966.html Using ngAnimate: //!annotate="YourA ...
- Using UTL_DBWS to Make a Database 11g Callout to a Document Style Web Service
In this Document _afrLoop=100180147230187&id=841183.1&displayIndex=2&_afrWindowMode=0& ...
- Gtest源码剖析:1.实现一个超级简单的测试框架xtest
下面的代码模仿gtest实现,主要说明了以下两点: ASSERT_* 和 EXPECT_*系列断言的原理和作用. gtest是怎样通过宏自动注册测试代码让其自动运行的. #include <io ...
- linux内存——/proc/sys/vm/drop_caches
原贴:http://www.linuxfly.org/post/320/ http://blog.csdn.net/chinalinuxzend/article/category/265273/2 ...