倒三角输出:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#define N 10
//3 – 1 – 3 1
//- 0.5 0.5
int main()
{
//输入在一行中顺序给出3个正整数N、U、D,其中D<U,N不超过100。
int a[N][N] = {0};
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
{
if (j==0 || i ==j)
{
a[i][j] = 1;
}
else
{
a[i][j] = a[i – 1][j – 1] + a[i – 1][j];
}
//printf(“%5d”, a[i][j]);
}
//printf(“\n”);
}
for (int i = 9; i >=0; i–)
{
printf(“%*d”, 20-i*2,a[i][0]);
for (int j = 1; j <=i; j++)
{
printf(“%4d”, a[i][j]);
}
printf(“\n”);
}
system(“pause”);
return 0;
}
//正三角输出
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <stdlib.h>
#define N 10
//3 – 1 – 3 1
//- 0.5 0.5
int main()
{
//输入在一行中顺序给出3个正整数N、U、D,其中D<U,N不超过100。
int a[N][N] = {0};
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
{
if (j==0 || i ==j)
{
a[i][j] = 1;
}
else
{
a[i][j] = a[i – 1][j – 1] + a[i – 1][j];
}
//printf(“%5d”, a[i][j]);
}
//printf(“\n”);
}
for (int i = 0; i < 10; i++)
{
printf(“%*d”, 20-i*2 ,a[i][0]);
for (int j = 1; j <= i; j++)
{
printf(“%4d”, a[i][j]);
}
printf(“\n”);
}
system(“pause”);
return 0;
}