找回密码
 立即注册
搜索
热搜: 活动 通知
查看: 74|回复: 0

检测点8-5

[复制链接]

620

主题

336

回帖

1057

积分

管理员

积分
1057
发表于 2026-3-7 19:36:31 | 显示全部楼层 |阅读模式
检测点8-5

1.在源文件c0803.c中,if语句的控制表达式为nums [x] > nums [y]。这是一个关系运算符,它的两个操作数是左值吗?为什么?是否执行左值转换?为什么?
答:是左值,且执行左值转换,因为符合左值转换的规定。

2.修改源文件c0803.c,在不调用swap_ab函数或者任何其他函数的情况下,交换两个数组元素的值。
答:
# include <stdio.h>
# define LEN 6

int main (void)
{
    int nums [LEN];

    printf ("Please enter %d numbers:", LEN);

    for (int x = 0; x < LEN; x ++)
        scanf ("%d", & nums [x]);

    printf ("Before sorted:");

    for (int x = 0; x < LEN; x ++)
        printf ("%10d", nums [x]);

    printf ("\n");

    for (int x = 0; x < LEN; x ++)
        for (int y = x; y < LEN; y ++)
            if (nums [x] > nums [y])
                {
                    int t = nums [x];
                    nums [x] = nums [y];
                    nums [y] = t;
                }

    printf ("After sorted:");

    for (int x = 0; x < LEN; x ++)
        printf ("%10d", nums [x]);

    printf ("\n");
}


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|鼠侠网 ( 吉ICP备19001332号 )

GMT+8, 2026-3-30 16:13 , Processed in 0.221245 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表