Reputation: 31
I'm trying to replace every even number in Pascal's triangle with an asterisk (*). So far, my code is looking like this:
#include<stdio.h>
#include<stdlib.h>
long calc( int );
int main()
{
int i,j,row,pas;
printf("Enter no. of rows in pascal triangle : ");
scanf("%d", &row);
for(i=0; i<row; i++)
{
for(j=0; j<=(row-i-1); j++)
printf(" ");
for(j=0; j<=i; j++)
{
pas=calc(i)/(calc(j)*calc(i-j));
printf("%ld ",pas);
}
printf("\n");
}
system("pause");
return 0;
}
long calc( int num)
{
int x;
long res=1;
for(x=1; x<=num; x++)
res=res*x;
return (res);
}
I need to insert this block of code (maybe?)
if (i%2==0)
{
i = asterisk;
printf("%c", asterisk);
}
Of course I will put in main ()
char asterisk = 42;
Can anybody help me?
Upvotes: 0
Views: 308
Reputation: 5836
#include<stdio.h>
#include<stdlib.h>
char asterisk = 42;
long calc( int );
int main()
{
int i,j,row,pas;
printf("Enter no. of rows in pascal triangle : ");
scanf("%d", &row);
printf("\n");
for(i=0; i<row; i++)
{
for(j=0; j<=(row-i-1); j++)
printf(" ");
for(j=0; j<=i; j++)
{
pas=calc(i)/(calc(j)*calc(i-j));
if (pas%2==0)
printf("%c ", asterisk);
else
printf("%ld ",pas);
}
printf("\n");
}
system("pause");
return 0;
}
long calc( int num)
{
int x;
long res=1;
for(x=1; x<=num; x++)
res=res*x;
return (res);
}
Upvotes: 1