0
#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:

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by SammyHasibi
0

thats all i would say

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

thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.