与非问题和杨辉三角

找名次

#include<stdio.h>
int main()
{
int a;
int b;
int c;
int d;
int e;
for (a = 1; a <= 5; a++)
{
for (b = 1; b <= 5; b++)
{
for (c = 1; c <= 5; c++)
{
for (d = 1; d <= 5; d++)
{
for (e = 1; e <= 5; e++)
{
if ((a == 3) + (b == 2) == 1 &&
(b == 2) + (e == 4) == 1 &&
(c == 1) + (d == 2) == 1 &&
(c == 5) + (d == 3) == 1 &&
(e == 4) + (a == 1) == 1)

{
if (abcde == 120) //将多余的情况去掉
{
printf(“a=%d,b=%d,c=%d,d=%d,e=%d”, a, b, c, d, e);
}
}
}
}
}
}
}
return 0;
}

找凶手

#include<stdio.h>
#include<windows.h>
int main()
{
int killer;
for (killer = ‘a’; killer <= ‘d’; killer++)
{
if ((‘a’ != killer) + (‘c’ == killer) + (‘d’ == killer) + (‘d’ != killer) == 3)
{
return killer;
}
}
printf(“凶手是:%c”, killer);
system(“pause”);
return 0;
}

杨辉三角

第0列:a[i][0]=1
i==j :a[i][j]=1
剩余:[i][j]=a[i-1][j-1]+a[i-1][j]

#include<stdio.h>
#define N 12
void Print(int n)
{
int a[N][N] = { 0 };
int i, j;
for (i = 0; i < n; i++)
{
a[i][0] = 1;
for (j = 0; j <= i; j++)
{
if (i == j)
{
a[i][j] = 1;
}
if (i>1 && i != j)
{
a[i][j] = a[i – 1][j] + a[i – 1][j – 1];
}
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
printf(“%5d”, a[i][j]);
}
printf(“\n”);
}
}

int main()
{
Print(10);
return 0;

}

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/qq_43586538/article/details/83792694
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞