Title: Seek 1+2+...+n, the request cannot use multiplication and division method \for\while\if\else\switch\case and so on key word and Condition judgment statement (A? B:C).
You can use constructors, loop solver, use arrays to construct multiple classes, and use static variables of classes to store data.
Code:
* * * * * main.cpp * * * Created on:2014.7.12 *
This column more wonderful content: http://www.bianceng.cnhttp:// www.bianceng.cn/Programming/sjjg/
* author:spike
/
#include <stdio.h>
#include < stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
Class Temp {public
:
temp () {++n; Sum+=n;}
static void Reset () {n=0; sum=0;}
Static size_t Getnum () {return Sum;}
Private:
static size_t N;
static size_t Sum;
size_t temp::n = 0;
size_t temp::sum = 0;
size_t Sum (size_t N) {
temp::reset ();
temp* a = new temp[n];
Delete[] A;
A = NULL;
return Temp::getnum ();
}
int main (void)
{
size_t result = Sum;
printf ("result =%d\n", result);
return 0;
}
Output:
result = 55
Author: csdn Blog Caroline-wendy