OJ系统C语言练习第四天

第一题

<span class='yzk_title_77'>C语言OJ练习记录(四)</span>-一只小白
int main()
{
    double x;
    scanf("%lf", &x);
    double x0,x1;
    x0 = x / 2.0;
    x1 = (x0 + x/x0) / 2.0;
    while(fabs(x1 -x0) >= 0.00000001){
        x0 = x1;
        x1 = (x0 + x/x0) / 2.0;
    }
    printf("%.6lf\n", x1);
    return 0;
}

第二题

<span class='yzk_title_77'>C语言OJ练习记录(四)</span>-一只小白
int main()
{
    int n,m;
    scanf("%d", &n);
    while(n--){
        scanf("%d", &m);
        int num[m-1];
        int num2[m-1];
        //输入数列
        for(int i = 0;i < m; i++){
            scanf("%d", &num[i]);
            num2[i] = num[i];
        }
        //将伪数列排序
        for(int i = 0;i < m-1; i++){
            for(int j = i+1;j < m; j ++){
                if(num2[i]>num2[j]){
                    int temp = num2[i];
                    num2 [i] = num2[j];
                    num2 [j] = temp;
                }
            }
        }
        //找出最大值和最小值在原数列里的下标
        int k,p;
                int temp;
        //k是最小值的下标,p是最大值的下标
        //先判断最大值,再判断最小值
        for(int i = 0; i < m; i++){
            if(num2[m-1] == num[i]){
                p = i;
                break;
            }
        }
        temp = num[p];
        num[p] = num[m-1];
        num[m-1] = temp;
        for(int i = 0; i < m; i++){
            if(num2[0] == num[i]){
                k = i;
                break;
            }
        }
        temp = num[k];
        num[k] = num[0];
        num[0] = temp;
        for(int i = 0; i < m; i++){
            printf("%d", num[i]);
            if(i != m-1){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

第三题

<span class='yzk_title_77'>C语言OJ练习记录(四)</span>-一只小白
int main()
{
    int a[10];
    while(scanf("%d", &a[0])!=EOF){
        for(int i =1;i < 10;i++){
            scanf("%d", &a[i]);
        }
        for(int i = 0; i < 10; i++){
            for(int j = i+1;j < 10;j++){
                if(a[i]>a[j]){
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        int sum = 0;
        for(int i = 1;i < 9;i++){
            sum += a[i];
        }
        printf("%.2lf\n", (double)sum / 8.0);
    }

    return 0;
}