0 like 0 dislike
3.7k views

By using two-dimensional array, write C program to display a table that represents a Pascal triangle of any size. In Pascal triangle, the first and the second rows are set to 1. Each element of the triangle (from the third row downward) is the sum of the element directly above it and the element to the left of the element directly above it. See the example Pascal triangle(size=5) below:

使用二維陣列,寫一個顯示巴斯卡三角形的程式。

Example input1:

5

Example output 1:

    1
   1 1
  1 2 1
 1 3 3 1
1 4 6 4 1

Example input 2:

0

Example output 2:

0

 

[Exercise] Coding (C) - asked in Chapter 8: Arrays by (5.2k points)
ID: 39984 - Available when: Unlimited - Due to: Unlimited

edited by | 3.7k views

102 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
void fun(int);
int main(void)
{
    int in;
*** * * ***** ** * * * * **** * **** &in);
    fun(in);
    return 0;
}
void fun(int n)
{
* ** ** * ** *** * ****** * *
    {
* *** * * * **** * * *** * * *** *** * ** buf[100]= {1};
**** * * * * *** * * * * ****** * ******** * ** i, j;
** * * ** * * * * * * **** * ** ** ** * * * * * * i<n; i++)
* *** *** *** ** * ** ***** * **** * * *
** * * ** * * **** * *** *** * * ** ***** * *** ** ** * ** ** * * *** ** * j>0; j--) buf[j] = buf[j] + buf[j-1];
**** * * ** **** * * * * ** * * ** * * * ** ** * * ** * *** j<n-i; j++)printf(" ");
* ***** * * ** * *** ** * ** * * *** ** * ** **** * ** ** ** j<=i; j++)
*** ***** *** * * * * **** *** ** * ** * ** * *** * * * * * *
* * * **** *** * ** * ** ** * **** ** * * * **** ** * *** * ** **** * ** ****** ***
*** ** * * * * **** ****** * * *** ** * **** ** *** * ** ** *** ** ** * ** * * * * ** * * ** ", buf[j]);
**** * ** ** * **** * * * * ** * **** * **** *** * * * * ** * ***** ** ** * ***
***** * ***** *** * ****** ** * ** ** * ** ** ****** **** *** * **** ** ** ** * * ** **** *** buf[j]);
* * *** * ***** * ** * * **** ** * * * ** **
** ** ** * ** * ** * * *** **** * * * * ** * * * * * **
***** ** * * * ** *** * ** **** * ** ** ******* * ** ***** * * * * **** * * ** ****
* * ***** * * * *** * **** ** *** *** *
    }
}
answered by (-258 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
**** ***** * * ****
int main()
{
* ** * **** int noOfROW;
*** **   ** *** *** ** * * * *
* *** * * int ** * * ***
**** ****
* *** ** * * ***
** * * *** * {
* **       *** ** * ** * *
** ***   }
** ** *   else
* * *   * * ** * * *
* * *   {
* *   * ** *   * *** *** ***** **** * ** ** ***
*** ***       {
* * *       ** ** ** * * ***
*** * *   * ** ****** * **** ** * *
** * * * ***** ** *** * *****
** *   ** * ** ** *** ***** * * ** **
***   * *** ** ** ** ** * num=row;
* ****   *** * * * ** ** ** * den=1;
***** * * * ***** * ** * * *** * * * ** * ** ** * ** * *
********** * * *** *** * * * * * ******
** **** ** * ** ** * ** *** *** * * ** ** * * ** ** * **
* * ** * ***** ** ***** ** ** ** ** ** * * * * ** ** * *** *
* * * ** ** ** ***** ** * * ** ** **** * * ** ********
* * *** * ** * * ** * ****** * * * * *** * * * ** * num--;
** * * * ** ** ** ****** ** ** * *** den++;
* * * * *** * ** **** }
* ** * **** * * * ** *** * * * * *
*** * * * ** }
** ** * *
}
answered by (-214 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
** ****** * ** * ****
int main()
{
** *** * ** int noOfROW;
* ** *   * *** * ** * ******* * *
** **  
  * *** int **** ** *
* * * ** * ** * *** * ** * * *** *
* * * * ** ** * {
*** * * **     * * * * ** ** ** * * *
* ***     *** {
***       ** ** ** *** *
* ****   ** * ** ****** ***
**** * *   ** *** * * * ** ***
* ***   * ***** * * *** * * **
* ***   **** ** * *** * * ** num=row;
* ** *   * * * ** * * ** * * * * * den=1;
* ****   ** * ** * * * * * * * * * ** ** *** ** *
** * ** * * *** * * * * *
* * * * * * * ** * * * * * * * *** ** **** *** * **
* ** ** * ****** ** * * ** **** * * **** * * * * ** ** ***** *
** * *** ** ** *** * *** ********* * ** * ** * *** **
* ****** ** ** **** * ** * ** * * * ****** num--;
* * **** * **** * * ***** * ** ** ** ** *** den++;
** ***   * *****   }
*   * * * *** * * * *** **** * *
* * ** * ** * }
* **** ***
}
answered by (-214 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

long factorial(int);

int main()
{
* *** ** ***** i, n, c;

**** ** * * * * * * * * * **** *** * ** * ** *

* ** * * ***** * ** == 0)
* * * **** * * *** *
***** * ** * * ** * * **** *** *** ** ** * * * ***** ***
    }
** * *** ** * ** * * ****
    {
** **** * *** * * * * *** * ** * **** ** (i = 0; i < n; i++)
** * * ** * * *** * * ** * *** ***
*** * * * * * ****** ** *** * * ** * ** * * * * * **** * ** ** * * * * * * * * (c = 0; c <= (n - i - 2); c++)
*** *** * * * * ****** * ** ** * * ******* *** * * * * * ** *** * * * *** *** ** ** *** ");

* * * ** * ** * * * ****** ** **** *** ******** ** ** ********* * (c = 0 ; c <= i; c++)
** **** *** ** ***** *** * *** * ** ** * ** * * **** * **** *** *** * **** * * * * * * **** * * * ***** * * ***

* * **** * * ** ** * * * * ********** ***** * * * * * * * *** ** *** * ** * ** ** ***
* **** * * * ** *** * * ***** **** * ***
**** ** * ** ** ** * *
** * ** ***** * *** * * 0;
}

long factorial(int n)
{
* * * * ** * ** * * c;
** * * * ****** * * * result = 1;

* * * * * ** * * * * (c = 1; c <= n; c++)
** ** ** *** *** *** * * * * * * ** ** ** * = result*c;

** * ** *** * * ****** *** result;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include * * ****** *

long * **** *

int main()
{
*** * * **** * ** i, n, c;

**** * **** * * * * * ****** *** * * *

* ***** * * * (i = 0; i < n; i++)
* ******* * ** * ****
* *** *** * ** * *** * ****** * (c = 0; c <= (n - i - 2); c++)
* * * * * * *** * * *** * ** ** **** * ** *** ** *

* * **** **** * * ** * **** **** (c = 0 ; c <= i; c++)
* * *************** ** ** * * **** * * * * *** **** ***** * * *** ** ** ** ** ** * **** *

* * ** * ** ** ****** ** * *** * ** ** ** * * ** ****
* *** ** *** * *

** * **** **** ** * *** 0;
}

long * ** n)
{
******* ** ** * **** c;
* * * * ** ** ** * result = 1;

*** ** * * * ** ** (c = 1; c <= n; c++)
*********** * ** ******* * * * ** **** * **** ** ** ** = result*c;

*** ** * ****** * result;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>


int main()
{
    int pascal[100][100];
    int num;
    int i,j,k;
  
**** * * *** ***** ** * * * * ** * *** ****
* * * ** * ** ** * * * *** i<=num; i++)
    {
* * * * * ** * * ** * * ***** ***** * * * * * j<=i; j++)
*** ** **** ** ***** **** *** * * * * *
* ** * * * ** * ** ** *** ** *** *** * * * * ** * * * *** * ** ***
* * * *** * ** * ** * **** *** * ** * ** **** ** * * * ***
** ** ***** * * ** ** ** ** ******** ***** * **** * **** * * * * ***** ** ** **** * ** * *
* ** **** * ** ** ***** ** * *** * ** * ******** *** **** * **** *
* ** * **** * ** ** ***** ****** * * * * ** * * **** **** *** ** *** *
** * * *** * * * * ** * ** **** *** *** *** ** ** ** ** *
*** ** * * ** ********* * * **** * **** * * *** *** *** * ** * * ** * ******** * * * ** **** ****
**** * * * * ** * * *** * *** * **** ******** ** ** ** **** ** * **
* ** *** * ** * * * * * *** * * ** *** * * *
    }
    for(i=1; i<=num; i++)
    {
* ** * * **** ***** * * **** * * *** ** * * ** k<=num-i; k++)
****** * * * ** * * ** ** *** * * * * **
*** ** ** *** * ** ***** ** *** ** * ** ** * **** ** * *** * ");
**** * * * * * *** * ***** *** ****** **
*** * ****** ** * * * * ** * *** ** *** ** * j<=i; j++)
*** * *** * ** * * *** * ** ** * *
* *** * ** ** **** ** * * * * * *********** * ** * ** ****** * * * ** * ",pascal[i][j]);
** * * ** * *** * * **** * * ** ** **** *
*** * * ******** * *** ** * * * * *** ** * *****
* ** * *** ** * * * *** * * * ** * * != i)
** ** * * ** * * * ** * *** ***** * *** ****** *
* * **** **** * * ** * * ** * ** ********** ** ** * *** * **** * *
** ** * * ***** ****** *********** *
    }
   
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int table[80][80];
int main()
{
    int y=0;
    int i=0;
    table[0][0]=1;
** ** * * ** *** ** * ** * **** * * ** * ** * ** **
*** * ** * * ** * * * * ** ** *** * * *** *
*** ****** *** ** ** * *** * * * ** ** * * * * * *** ** * ** * *** *** * *
* * **** * * ******** * * * *** ** * * ** ** ** ** * * *** * ** *** * * * ** * *** *** ** * * *** ** ** *
* ** * ** * * * * * ** * ***** ** *** * **** * **** ** * ****
** * * *** *** ** ** * * ** * ** **** *
    int n=0;
    scanf("%d",&n);
    if(n==0)
    {
**** *** * *** * **** *** ** ** ** *** ** ** ** *********
    }
    for(y=0;y<=n;y++)
    {
* * *** * ** * ** * * * * * * **** * * *** space;
* ** * * * **** ** * * **** ******** *** * * * * ** *
        {
** ** * * ** * * ******** * * ** * * * ****** * * * ** * ** **** ");
        }
* ** * * *** * *** **** * ** * *** *** ** **
*** * * * * *** *** ** * * * *** * ** * * * * * *
*** * ** ****** * * ******** * ** ** ** ** * ****** * * * ** **** * ** ***** ** * ** **
*** * ** ** * ** **** * ***** * ** *
****** *** * ** * * ** ** * * * ****** ** *** *** ** * *** ***** *
*** ***** * * ** * ** *** * * * *** ** ** *** *** **** **** *** * ** * * * * * ** * * **
* ** ** * *** ** * * **** ** * ** * * **

*** *** * * ** * ******** * *** ** *
** *** * * * * * *** *** * **** ***** ** ** * * *** ***
* * * * * ** * ** * * * * ** * * * ** *** ** ** ** ** *** * ** ** ******** * **
* * * ** ******* ** * ** *** * ******* * * **** * * ** **** * ** * * ** * * ** ** ** *** * * * ** *** **
** ****** ** * ** *** * * * ** ** * * * ** *** * * **** * * * * ** ** * ** *** ** ** ** * ** ** * *** *
* * **** * * ** *** * ** ** *** * ***** *** * ****** * * ******** * * ******* ******* **** ******
* * ** * * ******* ** * * * ** * ** * **** * * * ** * ** * * ** * * **** * *** * **
* ** * ** * * **** *** *** * * *** **** * * * ** *** ** * **** *** * *** **** * * *** * ** *** * **** ** * *** * ******** * **

*** ** * * * * * *** * * * ** * * *** * *** ** ** ***** *** ** * ** ** ****** ** ** * ** *
* * ***** * * **** * ****** * * * ***** * * * *
* * * ***** * ** * * * *** * * *** *
    }
}
answered by (-329 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
# include <stdio.h>
# include <stdlib.h>

int main()
{
*** * * ** ** *** * num;
***** * * ** ** **** *** ***** * * * *** * ** * ***

* ** * * * * * ** ** pascal[num][num];

* * * *** * * * * *** n,k;
*** * ** * * ** *** * * ** **
    {
****** * * *** ***** ** * * ** **** * ** **
** *** ** * ** ** *** ****** * ****** * *** * ******** *
    }

** *** ** * * * * ** ** *** * * * *
* ** * * * * ***** * * ************** ******** * *****
    {
* * * *** *** *********** *** * * *** * ******* **** * **** * *
    }

** ******* * * * *** ** (num==0)
    {
*** * ** *** ** * * * ** * * * * **** **** * * * * * * ** ***** **
    }

* * * * ** ** * **** *
* * ** * * ** * ** * * *** *** *
    {

** ** * ** * ** ***** * ** ** * **
* * *** * * ** **** * **** * ***** * * * * ********** * * * * **** *** *** *
**** * * * *** ** * * ** *** ** ** *** ** **** * *** **** * * *** * * *** ** ** ** * * * ** * ");
******* *** * ****** * *** * * * * ** *** *

* *** * ** ** * **** * ** * * ** * * * ***** ** * * * * * *

**** * **** * ** * *** ** **** * * * ** **** ** *
*** **** *** **** ****** * *** ****** * *** * **** * * ** ** ** * ***
* ** ** * * *** * ** ** **** * * ** ***** *** * * * * * * * * *** * *** * * *** * ** * %d",pascal[n][k]);
** *** * ** ** * * * * * * * *** *** ***** *

** * * ***** * * ***** ***** * * * * ** * * * * **** **** **
    }


** ** ** ***** **** ****** **** *** ***
* ** * * *** ** * ** * * ** **
*** * **** * * ** ** ** * **** * *** **** ***** *** * *** %d",pascal[(num-1)][k]);
   }

**** **** * *** ** * *** * 0;

}
answered by (-16 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
prog.c: In function 'main':
prog.c:54:5: error: expected declaration or statement at end of input
     return 0;
     ^~~~~~
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
# include <stdio.h>
# include <stdlib.h>

int main()
{
* ***** * ** * ** **** * * * num;
** * * * * * * *** ** ** * ***** ** *

* * *** ** * *** * *** * * * pascal[num][num];

* *** * * **** * * n,k;
** ** *** * * * * *** *** ***
    {
** * * ***** * * * * **** **** * * * ** * **** ** ***
******* **** ** * * ** * * ** * ** **** * ** ** *
    }

** * *** ** ***** ** * * *** *** *
*** *** * ** * **** * * ** * *** ** * * ** **** * ** ******
    {
* ** * * * * * ***** ****** * * ******* * * *** *
    }

* ** * * ** * ** (num==0)
    {
****** * *** *** * ** * * *** ** ** ** * * * * * * ** *
    }

** *** ** * ** * *
* * * *** *** *** * * **** * ** * *
    {

** ** * * *** * * * *** ******** * * *** ** ** *
*** ** ** * * * * ** * * * * * *** **** * * ** *** **** **** *
* ** **** ***** * * ** ** * * * * **** * ** **** ** * * * * ** *** * *** ** ** * ** * * ");
* **** * * * * *** * ***** * ** ** **

* * *** ***** * * * * ** ** ***** * * * * * ***** *

* ** ** * ** ** * * * * * * *** * * *** ******* *
* **** ** * ** ** ** ** * * ** *** ** ** * * * * * *** * ** *** *** ** ** * ****
** * * ** * * * * *** ** * * * * * ** * ** * ** ** ** * * * * * * * ** * ** * *** %d",pascal[n][k]);
*** ******** *** * ** ** * * * * ** * * * ** * *

** ** **** * * **** * ** ** * * * ****** * ****
    }

***** * * * *** ****** * 0;

}
answered by (-16 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 0
-----------Re-judge-----------
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>

long factorial(int [],int);

int main()
{
    int i, n, c,j,x=0;

* ****** * *** *** * * *** * * &n);
* * ** ** * * *** ** **** *
    {
* ** *** *** *** ** * * * * *** * *** **** * ** ***** *
    }
* * ** * * * * * * ** *
**** *** * ***** **** s[n];
* * *** **** ** ** *** * ** *
    {
** ***** *** * * * * *** ** **** ** ** * *
* ** * * *** * * * **** **** * ** * * * ******
    }

* *** * * *** *** (i = 0; i < n; i++)
    {
* * ** ** ** * * * *** * ***** * ** ***** (c = 0; c <= (n - i - 2); c++)
** * * ****** **** *** * ** ** ***** * ** * ** * ** ** * ");
* *** *** * *** * *** * ** * **** ** ** * * **** (c = 0; c <= i; c++)
*** * ***** ** *** ** * *** ** * * *** * * * **** * * *** * * * **** * * * *
**** **** * ** * * ** ** ** ****** * ** * * ** * **** * ** ** * *** *** * * ** ** ** **** **** * * ** * * * ** *
* ** *** ** *** **** **** ***** * ** *** *** * * ********* **** * ** *****
* *** ** * * *** * ** * **** ****** * ** * * * * * ** ****** **
* ** * * * ** ** ** * * * * ** ** *** * * * ***** * *** * ** * * **** ** * **** ** * ", **** * * **** **** **
*** *** *** * * **** **** *** * * ***** * * * * ** ** * * ** ****



* * *** * *** * * * * ** * * * * ** ** * *
* ** *** * * ** * * ***** ** ** ** ** * ** **** *** *** ********** * * * *****
** *** * *** ** ** * **** **** * * * *** ** * * **** *** * ** * * * * * *
**** * * * *** * * ** * * * ** * * *
* * * ** *** * * ** * * * * ***** *
*** ** *** ** *** * ** * ** *** * **** * * ** ******** ** ** ** *** * * **
**** ** * *** *** * * ** * * * * *** * *
    }
* ** ** * * * * ** * 0;
}}

long factorial(int n[],int b)
{
* **** *** * ****** * c;

****** * * * *** ****** result = 1;

*** * ***** * *** = 1; c <= n[b]; c++)
* ** ** *** ** * * ** *** * ** * ****** * **** ** = result*c;
* * ** ** * *** ** **** result;
}
answered by (-323 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
prog.c: In function 'main':
prog.c:7:5: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
     scanf("%d", &n);
     ^~~~~
prog.c:7:5: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:7:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:10:9: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
         printf("0");
         ^~~~~~
prog.c:10:9: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:10:9: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:23:13: warning: incompatible implicit declaration of built-in function 'printf'
             printf(" ");
             ^~~~~~
prog.c:23:13: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:26:14: warning: incompatible implicit declaration of built-in function 'printf'
             {printf("%ld", factorial(s,i)/(factorial(s,c)*factorial(s,i-c)));}
              ^~~~~~
prog.c:26:14: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:29:17: warning: incompatible implicit declaration of built-in function 'printf'
                 printf("%ld ", factorial(s,i)/(factorial(s,c)*factorial(s,i-c)));
                 ^~~~~~
prog.c:29:17: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:39:13: warning: incompatible implicit declaration of built-in function 'printf'
             printf("\n");
             ^~~~~~
prog.c:39:13: note: include '<stdio.h>' or provide a declaration of 'printf'
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:108.162.216.16
©2016-2024

Related questions

0 like 0 dislike
31 answers
[Exercise] Coding (C) - asked Dec 28, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 39985 - Available when: Unlimited - Due to: Unlimited
| 1.6k views
0 like 0 dislike
55 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 34968 - Available when: 2017-11-30 18:00 - Due to: Unlimited
| 2.1k views
12,783 questions
183,443 answers
172,219 comments
4,824 users