[PTA]6-12 判断奇偶性
生活随笔
收集整理的這篇文章主要介紹了
[PTA]6-12 判断奇偶性
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Spring-_-Bear 的 CSDN 博客導(dǎo)航
本題要求實(shí)現(xiàn)判斷給定整數(shù)奇偶性的函數(shù)。
函數(shù)接口定義:
int even( int n );其中 n 是用戶傳入的整型參數(shù)。當(dāng) n 為偶數(shù)時(shí),函數(shù)返回 1;n 為奇數(shù)時(shí)返回 0。注意:0 是偶數(shù)。
裁判測試程序樣例:
#include <stdio.h>int even( int n );int main() { int n;scanf("%d", &n);if (even(n))printf("%d is even.\n", n);elseprintf("%d is odd.\n", n);return 0; }/* 你的代碼將被嵌在這里 */輸入樣例1:
-6
輸出樣例1:
-6 is even.
輸入樣例2:
5
輸出樣例2:
5 is odd.
來源:
來源:PTA | 程序設(shè)計(jì)類實(shí)驗(yàn)輔助教學(xué)平臺
鏈接:https://pintia.cn/problem-sets/14/exam/problems/744
提交:
題解:
/** 判斷給定整數(shù)奇偶性,偶 1 奇 0*/ int even(int n) { // return n % 2 == 0 ? 1 : 0;return (n & 1) == 0 ? 1 : 0; }總結(jié)
以上是生活随笔為你收集整理的[PTA]6-12 判断奇偶性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle9i数据库Data Guar
- 下一篇: 微步在线安全事件分析:全球数亿主机被Fi