第四章C语言实训课程作业

第四章C语言实训课程作业,第1张

第四章C语言实训课程作业

概念题1

#include

int main()

{
int m = 23, n = 5;

printf("%dn",!m + m % n);

return 0;

}

文字描述法

(1)定义并赋值m=23,n=5;
(2)输出!m+m%n的值;   

流程图:

运行代码及结果:

 

 

概念题6

#include

int main()

{
int x = 1, y = 2;

(x > y) && (--x > 0);

printf("%dn",x);

return 0;

}

文字描述法

(1)定义并赋值x=1,y=2;
(2)计算(x>y)&&(--x>0);
   (3)输出x的值;
流程图:

运行代码及结果:

 

 概念题15 
#include
#include
int main()
{
    int a=2 , b=2 ,c=4;
    if (sqrt(fabs(a)) != (4 * a) / (b * c)) {
        a = 2;
    }
    else {
        printf("不构成");
    }
    printf("%dn", a);
    return 0;
}
流程图:

运行代码及结果:

 

 

概念题17

#include

int main()

{
int a = 0, b = 0, c = 0;

if(a++&&(b+=a)||++c)

printf("%d,%d,%dn",a,b,c);

return 0;

}

文字描述法

(1)定义并赋值a=0,b=0,c=0;
(2)如果(a++%%(b+=a)||++c);
(3)输出a,b,c,的值;
流程图:

运行代码及结果:

 

 

 选择题8

#include
int main()
{
    int a, b, x, y;
    x = 3, y = 5;
    if (x > y) {
        a = x;
        b = y;
    }
    else {
        a = y;
        b = x;
    }
    printf("%d,%dn", a, b);
    return 0;
}
文字描述法

1)定义4个整数a,b,x,y;
(2)给x赋值3;y赋值5;
(3)如果x>y;
(4)那么a=x;b=y;
(5)否则a=y;b=x;
(6)输出a,b的值;
流程图:

运行代码及结果:

 

选择题10
代码

#include
int main()
{
    int a , b , c ;
    a = 3;
    b = 3;
    c = 2;
    printf("%d,n",!a&&!b&&c);
    return 0;

文字描述法

(1)定义整数a,b,c;
(2)赋值a=3,b=3,c=2;
(3)输出!a&&!b&&c的值;

流程图:

运行代码及结果:

 

 

选择题17

#include

int main()

{
int n;

n = 8;

n %= (n - 2);

printf("%dn",n);

return 0;

}

 文字描述法

(1)定义整数n;n=8;
(2)计算n%=(n-2);
(3)输出n的值;

  代码 执行结果: :

 

 

选择题18

#include
int main()
{
    int a = 3, b = 2,x;
    x = a > b++?a++:b++;
    printf("%d,%d,%dn",x,a,b);
    return 0;
}
 文字描述法

(1)定义整数a,b,;
(2)给a赋值0,b赋值2;
(3)计算x=a>b++?a+=:b+=;
(4)输出x,a,b;

  代码 执行结果:

 

选择题20
#include
int main()
{
    int x, y, z;
    x = 4;
    y = 3;
    z = 5;
    if (x > y) {
        z = x;
        x = y;
        y = z;
    }
    printf("%d,%d,%dn",x,y,z);
    return 0;

文字描述法

(1)定义整数x,y,z;
(2)赋值x=4,y=3,z=5;
(3)如果x>y
(4)那么z=x,x=y,y=z;
(5)输出x,y,z的值;  

代码 执行结果::

 

选择题24

#include

int main()

{
int a = 0, b = 2;

b = --a || ++b;

printf("%dn",b);

return 0;

}

文字描述法

(1)定义整数a,b,x;
(2)给a赋值3,b赋值2;
(3)计算b=--a||++b;
(4)输出b;

代码 执行结果:

 

 

 选择题25 

#include

int main()

{
int s, x;

x = 5;

s = x <= 0 ? -1 : (x == 0) ? 0 : 1;

printf("s=%dn",s);

return 0;

}

 文字描述法

(1)定义整数s,x;
(2)给x赋值5;
(3)计算s=x<=0?-1:(x==0)?0:1;
(4)输出s的值;

  代码 执行结果: 

 

阅读1

#include
int main()
{
    int x = 0, y = 1, z = 10;
    if (x) {
            if (y) {
                z = 20;
            }
            else {
                z = 30;
            }
    }
    printf("%dn",z);
    return 0;
}

文字描述法

(1)定义整数并赋值x=0,y=1,z=10;
(2)如果x如果y;
(3)那么z=20;
(4)否则z=30;
(5)输出z的值;

   代码 执行结果: 

 

 

阅读3 

#include

int main()

{
int x = 0, y =0, z =0 ;

if (x++ && (y += x) || ++z);

printf("%d,%d,%dn",x,y,z);

return 0;

}

 文字描述法

(1)定义整数并赋值x=0,y=0,z=0;
  (2)如果(x++并且(y+=x)或者++z);
(3)输出x,y,z的值;

  代码 执行结果:

 

编程1
#include
int main()
{
    int x ;
    scanf_s("请输入一个整数:", & x);
    if (x % 2 == 0){
        printf("x是奇数n", x);
    }
    else {
        printf("x是奇数n", x);
    }
    return 0;
}

 文字描述法

(1)定义整数x;
(2)输入一个整数给x
(3)如果x%2=0;
(3)那么x是偶数;
(4)否则x是奇数;

   代码 执行结果:

 

 

编程2
#include
#include
int main()
{
    double a, b, c, x1, x2;
    printf("请输入三个系数:");
    scanf_s("a=%lf,b=%lf,c=%lf", &a, &b, &c);
    double s = (b * b) - (4 * a * c);
    if (a == 0) {
        printf("该方程不是一元二次方程n");
    }
    else {
        printf("该方程是一元二次方程");
        if (s == 0) {
            printf("只有一个解:x1=%lf,x2=%lfn", x1 = -b / (2 * a), x2 = -b / (2 * a));
        }
        if (s > 0) {
            printf("有两个解:x1=%lf,x2=%lf", x1 = (-b + sqrt(s)) / (2 * a), x2 = (-b - sqrt(s)) / (2 * a));
        }
    }
    return 0;
}

 文字描述法

  (1)定义小数a.b.c,x1,x2;
  (2)输入三个系数;
(3)输出a,b,c的值;
(4)s=(b*b)-(4*a*c);
  (5)如果a=0;
(6)输出该方程不是一元二次方程;
(7)输出该方程是一元二次方程;
(8)如果s=0
(9)那么只有一个解,根据x1 = -b / (2 * a), x2 = -b / (2 * a),输出x1,x2的值;
(10)否则有两个解,根据x1 = (-b + sqrt(s)) / (2 * a), x2 = (-b - sqrt(s)) / (2 * a),输出x1,x2的值;
  代码 执行结果:

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5691468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存