PAT基础6-12

6-12 判断奇偶性 (10 分)

本题要求实现判断给定整数奇偶性的函数。

函数接口定义:

int even( int n );

其中n是用户传入的整型参数。当n为偶数时,函数返回1;n为奇数时返回0。注意:0是偶数。

裁判测试程序样例:

#include <stdio.h>

int even( int n );

int main()
{    
    int n;

    scanf("%d", &n);
    if (even(n))
        printf("%d is even.\n", n);
    else
        printf("%d is odd.\n", n);

    return 0;
}

/* 你的代码将被嵌在这里 */

输入样例1:

-6

输出样例1:

-6 is even.

输入样例2:

5

输出样例2:

5 is odd.


int even( int n )
{
    if(n%2==0)
    {
        return 1;
    }else
    {
        return 0;
    }
}

原文链接: https://www.cnblogs.com/lxzbky/p/10470319.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    PAT基础6-12

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/400194

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月14日 上午9:46
下一篇 2023年4月14日 上午9:46

相关推荐