偶数矩阵判断【C语言作业】

题目

若一个布尔矩阵所有行和所有列的和都是偶数,则称为偶数矩阵。请编写一个程序,判断一个布尔矩阵是否是偶数矩阵。

要求:

(1)输入:首先输入一个正整数n(n<100),代表该矩阵的大小,接下来是n行n列的矩阵。输出:如果这个矩阵是偶数矩阵,则输出"yes",否则输出"no"。

(2)需定义矩阵输入函数InputArray()。

(3)需定义偶数矩阵函数IsParity()。

完整解决方案

csharp 复制代码
#include<stdio.h>

void InputArray(int a[100][100], int *n) {
    int i, j;
    scanf("%d", n);
    for (i = 0; i < *n; i++) {
        for (j = 0; j < *n; j++) {
            scanf("%d", &a[i][j]);
        }
    }
}

void IsParity(int a[100][100], int n) {
    int r, c;
    int i, j;
    int count = 0;

    for (i = 0; i < n; i++) {
        r = 0;
        c = 0;
        for (j = 0; j < n; j++) {
            r += a[i][j];
            c += a[j][i];
        }
        if (r % 2 != 0 || c % 2 != 0) {
            count++;
        }
    }

    if (count == 0) {
        printf("yes\n");
    } else {
        printf("no\n");
    }
}

int main() {
    int a[100][100];
    int n;
    InputArray(a, &n);
    IsParity(a, n);
    return 0;
}

效果


相关推荐
练习时长一年1 天前
Leetcode热题100(跳跃游戏 II)
算法·leetcode·游戏
小白菜又菜1 天前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n1 天前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo1 天前
leetcode 2483
数据结构·算法·leetcode
sevenez1 天前
Vibe Coding 实战笔记:从“修好了C坏了AB”到企业级数据库架构重构
c语言·笔记·数据库架构
Xの哲學1 天前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢1 天前
归并排序与计数排序详解
数据结构·算法·排序算法
油泼辣子多加1 天前
【信创】算法开发适配
人工智能·深度学习·算法·机器学习
一路往蓝-Anbo1 天前
【第20期】延时的艺术:HAL_Delay vs vTaskDelay
c语言·数据结构·stm32·单片机·嵌入式硬件
Aaron15881 天前
AD9084和Versal RF系列具体应用案例对比分析
嵌入式硬件·算法·fpga开发·硬件架构·硬件工程·信号处理·基带工程