/*************************************************************************
> File Name: 46_Accumulate.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: 2016年09月04日 星期日 21时18分28秒
************************************************************************/ #include <stdio.h> // 函数指针法求1+2+...+n
typedef unsigned int (*fun)(unsigned int); unsigned int sum_T(int n)
{
return ;
} int Sum1(int n)
{
static fun f[] = {sum_T, Sum1};
return n + f[!!n](n-);
} // 递归
int Sum2(int n)
{
int sum = n;
int ans = (n>) && (sum+=Sum2(n-));
return sum;
} int main()
{
int n = ;
int ret1 = Sum1(n);
int ret2 = Sum2(n);
printf("ret1 is %d\n", ret1);
printf("ret2 is %d\n", ret2); return ;
}

剑指Offer46 求1+2+...+n的更多相关文章

  1. 剑指offer46 求1+2+...+n 以及& &&区别

    参考代码: class Solution { public: int Sum_Solution(int n) { int result = n; result && (result + ...

  2. 剑指Offer——求1+2+3+...+n

    题目描述: 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 分析: 递归实现. 代码: class So ...

  3. 剑指offer--14.求1+2+3+...+n

    &&短路原理 ------------------------------------------------------------------------------------- ...

  4. 剑指:求1+2+…+n

    题目描述 求 1+2+…+n,要求不能使用 乘除法.for.while.if.else.switch.case 等关键字及条件判断语句 A?B:C. 样例 输入:10 输出:55 解法 前面的和+后一 ...

  5. 剑指offer: 求1+2+...+n

    题目描述: 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 思路分析: 由于题目的限制条件很多.同样想到 ...

  6. 剑指offer--46.字符流中第一个不重复的字符

    双端队列 -------------------------------------------------------- 时间限制:1秒 空间限制:32768K 热度指数:113070 本题知识点: ...

  7. 剑指offer——求1+2+...+n

    方法一.通过在类的构造函数中执行加的过程. #include <iostream> using namespace std; class Base { public: Base(){n++ ...

  8. 剑指Offer-46.孩子们的游戏(圆圈中最后剩下的数)(C++/Java)

    题目: 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为牛客的资深元老,自然也准备了一些小游戏.其中,有个游戏是这样的:首先,让小朋友们围成一个大圈.然后,他随机指定 ...

  9. 剑指offer46:圆圈中最后剩下的数字(链表,递归)

    1 题目描述 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为牛客的资深元老,自然也准备了一些小游戏.其中,有个游戏是这样的:首先,让小朋友们围成一个大圈.然后,他随 ...

随机推荐

  1. ActiveMQ的消息确认问题

    http://riddickbryant.iteye.com/blog/441890 [发送端] session = connection.createSession(Boolean.FALSE,   ...

  2. Mathematics for Computer Graphics数学在计算机图形学中的应用 [转]

    最近严重感觉到数学知识的不足! http://bbs.gameres.com/showthread.asp?threadid=10509 [译]Mathematics for Computer Gra ...

  3. as3.0:文字 效果

    //文字描边效果var tf1 = _root.createTextField("tf1", _root.getNextHighestDepth(), 10, 10, 0, 0); ...

  4. CORTEX -M3 : Registers in depth

    http://www.zembedded.com/cortex-m3-registers-in-depth/ Thanks for the overwhelm response you show in ...

  5. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  6. Android中显示网页的多种方式

    在android中显示页面主要有两种方式,一种是在Activity里面直接显示网页,另一种是调用浏览器显示网页.方式不同,使用的方法也不同,下面我们分别讲解. 一.在Activity里面直接显示网页 ...

  7. 我的git使用记录

    git的教程现在琳琅满目,需要学习的东西也有很多,一下子接受不了那么多的东西,所以打算记录在实用的过程中常用的操作和遇到的问题. 基本操作 git init git add . git add -A ...

  8. android一些系统相关的东西

    添加快捷方式和删除快捷方式: private void addShortcut() { Intent shortcut = new Intent( "com.android.launcher ...

  9. Redis for Windows(C#缓存)安装和使用

    Redis for Windows(C#缓存)安装和使用 前言 前段时间写过两篇简单的有关Memcached缓存的相关文章,当然了只是入门的如何使用而已.最近这两天又发现了Redis这个神奇的东西,之 ...

  10. [Angular 2] Style Angular 2 Components

    Each Angular 2 Component can have its own styles which will remained contained inside the component. ...