Hi this is my code for calculating pascal triangle but it runs error : has stopped working... why ? i think its error is in paskal function
#include <stdio.h>
long paskal(int,int);
int main (void)
{
int n = 0 ;
int m = 0 ;
int k = 0 ;
scanf("%d" , &n);
for(k = 1 ; n >= k ; )
{
for( m = 1 ; k >= m ; m++ )
{
long f = paskal(k , m ) ;
printf("%ld" , f);
}
printf("\n");
k++;
}
return 0;
}
long paskal( int n , int i )
{
if(n == 1 && i == 1 )
return 1 ;
else
return paskal(n-1,i) + paskal(n-1,i-1);
}
The limit-conditions are not correct.
The correct way to put the limit conditions is
if(n == 1 || i == 1 )
return 1 ;
else
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With