Title Description:
Ask for 1+2+3+...+n, the request cannot use multiplication method, for, while, if, else, switch, case and other keywords and conditional judgment statement (A? B:C).
Input:
The input may contain multiple test samples.
For each test case, the input is an integer n (1<= n<=100000).
Output:
corresponding to each test case,
The value of the output 1+2+3+...+n.
Sample Input:
3
5
Sample output:
6
15
AC Code:
#include <stdio.h>
int Add (int n, int *p) {
n && Add (n-1, p);
return (*p + = n);
}
int main () {
int n;
while (scanf ("%d", &n)! = EOF) {
int sum = 0;
Add (n, &sum);
printf ("%d\n", sum);
}
return 0;
}
/**************************************************************
problem:1506
user:wusuopubupt
Language:c
result:accepted
time:630 Ms
memory:1212 KB
************************************** **************************/