#include <stdio.h>
void sanjiao(int a[][100], int n);//定义杨辉三角函数
int main() {
FILE* fp= fopen("....txt", "w");
int n;
scanf("%d", &n);
int a[100][100] = {0};
if(fp==NULL)//判断文件是否打开成功
{
perror("fopen");
return 1;
}
sanjiao(a, n);
for (int i = 0; i < n; i++) //写入文件
{
for (int j = 0; j <= i; j++)
{
fprintf(fp, "%4d", a[i][j]);
}
fputc(10, fp);
}
fclose(fp);
fp=NULL;//养成习惯;
return 0;
}
void sanjiao(int a[][100], int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
if (j == 1 || i == j)
{
a[i - 1][j - 1] = 1;
}
else
{
a[i - 1][j - 1] = a[i - 2][j - 1] + a[i - 2][j - 2];
}
printf("%4d", a[i - 1][j - 1]);
}
printf("\n");
}
}