I wish you can help me with this coding issue. I'm trying to implement a code for a c++ pascal traingle using recursion technique with this main function :
#include <iostream>
#include <cstdlib>
using std::cin;
using std::cout;
using std::endl;
int *pascal(int);
int main(int argc, char *argv[]) {
int num = argc == 2 ? atoi(argv[1]) : 1;
for (int i = 1; i <= num; ++i) {
int *a = pascal(i);
cout << (i < 10 ? " " : "") << i << ": ";
for (int j = 0; j < i; ++j) {
cout << a[j] << ' ';
}
cout << endl;
}
return 0;
}
I need to implement a pointer to int function that takes an argument 'n' and
returns the n-th line of Pascal's Triangle, something like this :
int *pascal(int n) {
return new int[n];
}
so I trying to implement the funtion using a recursive call, i came up with this:
int *pascal(int n) {
if ( n == 0)
return (1);
else
return n * (pascal(n-1));
}
I keep getting 2 errors : cannot convert ‘int*’ to ‘int*(int)’ in assignment...and....invalid operands of types ‘int’ and ‘int*’ to binary ‘operator*’
I have to use this pointer function, pointers do confuse me a lot...not sure what is the problem, what should this function return (my thinking is a reference may be !) in order to be used with my main function to print out pascal triangle ? looking forward to your response....Thank you.
This post has been edited by macosxnerd101: 15 July 2013 - 10:08 PM
Reason for edit:: Please use code tags

New Topic/Question
Reply


MultiQuote






|