C语言作业2

概念填空1

#include<stdio.h>
int main()
{
    int m = 23, n = 5,x;
    x=!m + m % n;
    printf("%d", x);
    return 0;
}

 概念填空6

#include<stdio.h>
int main()
{
    int x = 1, y= 2,z;
    (x > y) && (--x > 0);
    printf("%d", x);
    return 0;
}

 概念填空15

#include<stdio.h>
int main()
{
    int a= 0, b= 3,c=2;
    if (a++ && b++)c--;
    else if (a + 1 == 6 || b--)c++;
    printf("%d%d%d", a,b,c);
    return 0;
}

概念填空题16

表达式为 sqrt(fabs(a))!=4*a/b/c

概念填空17

#include<stdio.h>
int main()
{
    int a= 0,b=0,c=0;
    if (a++ && (b += a) || ++c);
    printf("%d,%d,%d\n", a, b, c);
    return 0;
}

 单选8 

能将变量x,y中值较大的数保存到变量啊,值较小的数保存到变量b的程序段是 if(x>y){a=x,b=y;}else{a=y,b=x;}

单选10

#include<stdio.h>
int main()
{
    int a= 3,b=3,c=2;
    printf("%d\n",!a &&!b && c);
    printf("a=%d,b=%d,c=%d\n", a, b, c);
    return 0;
}

单选17

#include<stdio.h>
int main()
{
    int n= 8;
    n>8?n=0:n++;
    printf("%d\n",n);
    return 0;
}

 

 单选18

#include<stdio.h>
int main()
{
    int x,a=3,b=2;
    x = a > b++ ? a ++ : b++;
    printf("%d%d%d\n",x,a,b);
    return 0;
}

 单选20

#include<stdio.h>
int main()
{
    int x=4,y=3,z=5;
    if (x > y)z = x, x = y, y = z;
    if (x > y) { z = x, x = y, y = z; }
    if (x > y)z = x; x = y; y = z;
    if (x > y) { z = x; x = y; y = z; }
    printf("%d%d%d\n",x,y,z);
    return 0;
}

单选24 

#include<stdio.h>
int main()
{
    int a=0,b=2;
    b = --a ||++b;
    printf("%d\n",  b);
    return 0;
}

 单选25

不能作为sign(x)的表达式为 s=x<=0?-1:(x==0)?0:1

阅读程序题1

#include<stdio.h>
int main()
{
    int x=0,y=0,z=0;
    if (x++ && (y += x) || ++z);
    printf("%d,%d,%d\n",x,y,z);
    return 0;
}

 阅读程序题 2

#include<stdio.h>
int main()
{
    int x;
    printf("Please input a integer\n");
    scanf_s("%d", &x);
    if (x % 2 == 0)
        printf("is even number.");
    else
        printf("is odd number.");
    return 0;
}

 编程题1

#include<stdio.h>
int main()
{
    int x;
    printf("Please input a integer\n");
    scanf_s("%d", &x);
    if (x % 2 == 0)
        printf("is even number.");
    else
        printf("is odd number.");
    return 0;
}

 编程题2

#include<stdio.h>
#include<math.h>
int main(void)
{
    double a, b, c, x1, x2, r, i, delt;
    printf("Please input theaquation coefficients a,b,c:");
    scanf_s("%if,%if,%if", &a, &b, &c);
        printf("\n The equation:");
        if(fabs(a)<=1e-6)
        printf("is not a quadratic\n");
        else
        {
            delt = b * b - 4 * a * c;
            if(fabs(a)<=1e-6)
                printf("has two equal roots:%8.4f\n",-b/(2*a));
            else
                if (delt > 1e-6)
                {
                    x1 = (-b + sqrt(delt)) / (2 * a);
                    x2 = (-b - sqrt(delt)) / (2 * a);
                    printf("has distinct real roots:%8.4f and %8.4f\n", x1, x2);
                }
                else
                {
                    r = -b / (2 * a);
                    i = sqrt(-delt) / (2 * a);
                    printf("has complex roots:\n");
                    printf("%8.4f+%8.4fi\n", r, i);
                    printf("%8.4f-%8.4fi\n", r, i);
                }


        }
    return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值