#include <stdio.h>
int function1(int a)
{
    return(a*a*a);
}
int function2(int b)
{
    int i;
    int sum = 0;
    for (i=1; i<=b; i++)
        sum += function1(i);
    return(sum);
}
int main ()
{
    int n, result;
    printf("Enter n\n");
    scanf("%d", &n);
 
    result = function2(n);
    printf("Result = %d\n", result);
 
    system("pause");
    return(0);
}

Explain what the following program computes.
The following program implements 2 functions. . . function1 computes the cube of the integer a and function 2 sums the the cubes from 1 to n.
What does function1 compute?
Function1 computes the cube for an individual number.
What does function2 compute?
Function2 computes the sum of cubes (or function1) from 1 to n.
What will be the value of result at the end of the program?
The sum of the cubes from 1 to n.

Is there a more elegant, economical way to say this?:eek:

The sum of the cubes from 1 to n.

thats all i would say

thats all i would say

Thanks, I always try to elaborate my answers & I get shot down for not simplifying.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.