fractions

# include <iostream.h>
int cube(int n=1);int square(int n=1);
int main()
{
int n=1;{
for (n=1;n<=5;n++)
cout<<"number"<<n<<"square"<<square<<"cube"<<cube<<endl;
return 0;}
}
int square(int n)
{
return n*n;
}
int cube(int n)
{
return n*n*n;
}
THis is my program im trying to get the squared and the cube from loop 1to5, but
i wasnt able to get the result Im expecting whats wrong with my program?
it should be like this:
number1square1cube1
number2square4cube8
number3square9cube27
number4square16cube64
number5square25cube125

but im getting a wrong output!!any advice....
closed account (z05DSL3A)
Try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# include <iostream.h>
int cube(int n=1);
int square(int n=1);

int main()
{
    int n=1;
    
    for (n=1;n<=5;n++)
        cout<<"number " << n <<" square "<<square(n)<<" cube "<< cube(n)<< endl;
    return 0
}

int square(int n)
{
return n*n;
}
int cube(int n)
{
return n*n*n;
}

Last edited on
It works except that theres no semicolon on line 11,I didn't notice my bracket would bring wrong output...anyway thank u so much for helping out....! hope I learn this basic thing as fast as all programmer do, any advice of any reference in this kind of programming!cheers...
closed account (z05DSL3A)
It works except that theres no semicolon on line 11
Opps.

hope I learn this basic thing as fast as all programmer do, any advice of any reference in this kind of programming!cheers...

Have you had a look at the sites tutorials?
http://www.cplusplus.com/doc/tutorial/
Thanks a lot sir! it helps...
Topic archived. No new replies allowed.