秦九韶算法和欧几里得算法演示

#include <stdio.h>

int a[100];

int qinjiushaoAlg(int * a, int n, int x)
{
    int ans = a[n], i;
    for (i = n - 1; i >= 0; i--)
        ans = ans * x + a[i];
    return ans;
}

int main()
{
    int n, x, i;
    printf("请输入多项式最高项的次数n。\n");
    scanf("%d", &n);
    for (i = n; i >= 0; i--)
    {
        printf("请输入x^%d项的系数。\n", i);
        scanf("%d", &a[i]);
    }
    printf("请输入自变量x的值。\n");
    scanf("%d", &x);
    printf("多项式的值为:%d\n", qinjiushaoAlg(a, n, x));
    return 0;
}



#include <stdio.h>

int gcd(int a, int b)
{
    int tmp;
    while (b)
    {
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

int main()
{
    int a, b;
    while (1)
    {
        printf("请输入两个整数。\n");
        scanf("%d%d", &a, &b);
        printf("这两个整数的最大公约数为%d\n", gcd(a, b));
        printf("-------------------------------------\n");
    }
    return 0;
}





你可能感兴趣的:(秦九韶算法和欧几里得算法演示)