Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,392 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,128 people online right now. Registration is fast and FREE... Join Now!




Explain what program does

 
Reply to this topicStart new topic

Explain what program does, 2 functions which ultimately sum cubes 1 - n

sammyhasibi
22 Oct, 2006 - 02:19 PM
Post #1

New D.I.C Head
*

Joined: 2 Oct, 2006
Posts: 8


My Contributions
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?
CODE

#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);
}

User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Explain What Program Does
22 Oct, 2006 - 06:44 PM
Post #2

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
Function 1:


Function 2:
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Explain What Program Does
22 Oct, 2006 - 06:50 PM
Post #3

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
Function 1: Area of the cube
Function 2: Volume of the cube

That's my understanding of what you posed..

configure your code...

we will guide you for this...
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Explain What Program Does
23 Oct, 2006 - 12:15 AM
Post #4

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(sammyhasibi @ 22 Oct, 2006 - 03:19 PM) *

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?
CODE

#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);
}



It's very dependent on the assignment, but you are very close to a good description.

you could also have said:

Function 1 returns the cube of the parameter a

Function 2 returns the arithmetic sum of of the cubes from 1 to b

back to you
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:35AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month