fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. char asterisk = 42;
  4. long calc( int );
  5. int main()
  6. {
  7. int i,j,row,pas;
  8. printf("Enter no. of rows in pascal triangle : ");
  9. scanf("%d", &row);
  10. printf("\n");
  11. for(i=0; i<row; i++)
  12. {
  13. for(j=0; j<=(row-i-1); j++)
  14. printf(" ");
  15. for(j=0; j<=i; j++)
  16. {
  17. pas=calc(i)/(calc(j)*calc(i-j));
  18. if (pas%2==0)
  19. printf("%c ", asterisk);
  20. else
  21. printf("%ld ",pas);
  22. }
  23. printf("\n");
  24. }
  25. system("pause");
  26. return 0;
  27. }
  28.  
  29. long calc( int num)
  30. {
  31. int x;
  32. long res=1;
  33. for(x=1; x<=num; x++)
  34. res=res*x;
  35. return (res);
  36. }
Success #stdin #stdout #stderr 0s 2296KB
stdin
15
stdout
Enter no. of rows in pascal triangle : 
               1 
              1 1 
             1 * 1 
            1 3 3 1 
           1 * * * 1 
          1 5 * * 5 1 
         1 * 15 * 15 * 1 
        1 7 21 35 35 21 7 1 
       1 * * * * * * * 1 
      1 9 * * * * * * 9 1 
     1 * 45 * * * * * 45 * 1 
    1 11 55 165 * * * * 165 55 11 1 
   1 * * * 495 * * * 495 * * * 1 
  1 * * * 221 399 * * 399 221 * * * 1 
 1 * 1 5 * 29 * * * 29 * 5 1 * 1 
stderr
sh: pause: not found