杨辉三角c语言程序动态数组,动态实现杨辉三角(C语言)
生活随笔
收集整理的這篇文章主要介紹了
杨辉三角c语言程序动态数组,动态实现杨辉三角(C语言)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i = 0;
int j = 0;
int m = 0;
int **a = NULL;
printf("請輸入你要顯示的行數:");
scanf("%d",&i);
a = (int **)malloc(i*sizeof(int *));
for(j =0;j < i;j++)
{
a[j] = (int *)malloc((j+1)*sizeof(int));
}
a[0][0] = 1;
for(j =1;j < i;j++)
{
a[j][0] = 1;
a[j][j] = 1;
for(m = 1;m < j;m++)
{
a[j][m]=a[j-1][m]+a[j-1][m-1];
}
}
for(j = 0;j < i;j++)
{
for(m =0 ;m < j+1 ;m++)
{
printf("%d ",a[j][m]);
}
printf("\n");
}
for(j = 0;j < i;j++)
{
free(a[j]);
a[j] = NULL;
}
free(a);
a = NULL;
printf("\n內存清理完畢!");
}
總結
以上是生活随笔為你收集整理的杨辉三角c语言程序动态数组,动态实现杨辉三角(C语言)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode36.有效的数独(中等)
- 下一篇: 套路(Jony J)