Question 1506: 1 + 2 + 3 +... + N-9 degrees

Source: Internet
Author: User

Description:
Evaluate 1 + 2 + 3 +... + N. It is required that the keyword and condition judgment statement (? B: C ).
Input:
The input may contain multiple test examples.
For each test case, the input is an integer N (1 <=n <= 100000 ).
Output:
Corresponding to each test case,
Output 1 + 2 + 3 +... + N value.
Sample input:
3
5
Sample output:
6

15

Recommendation index :※※

Source: http://ac.jobdu.com/problem.php? PID = 1, 1506

 
# Include <iostream> # include <stdlib. h> # include <stdio. h> using namespace STD; int F (const int N); int f_end (const int N); int (* choose []) (INT) = {f_end, f }; int f_end (const int N) {return 0;} int F (const int N) {return choose [n> 1] (n-1) + N;} int main () {int N; while (scanf ("% d", & N )! = EOF) {printf ("% d \ n", F (N) ;}return 0 ;}

Introduction to function pointer array: http://blog.csdn.net/zhu_liangwei/article/details/8194812

@ Wqooops http://blog.csdn.net/shiren_bod/article/details/6703467 avoids the function pointer operation, using N itself as the end indicator.

 
# Include <iostream> # include <stdlib. h> # include <stdio. h> using namespace STD; int F (const int N, Int & sum) {N & F (n-1, sum); Return sum + = N;} int main () {int N; while (scanf ("% d", & N )! = EOF) {int sum = 0; printf ("% d \ n", F (n, sum);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.