示例#1
0
int sumToN( int pN )
{
    if( pN < 2 ) {
        return pN;
    }
    else {
        return pN + sumToN( pN - 1 );
    }
}
示例#2
0
int main( int argc, char *argv[] )
{
    int n = 3, ans;
    
    ans = sumToN( n );
    printf( "1 + 2 + ... + n = %d\n", ans );
    
    while( !getchar() );
    return 0;
}
示例#3
0
/* The sum of all positive multiples of x up to n */
int sumMultiplesOfXToN(int x, int n) {
   return x*sumToN(n/x);
}