From ec7c098897b4a83780124958f5be3e32bdf8cd47 Mon Sep 17 00:00:00 2001 From: Luigi Altamura <61703080+LuigiAltamura@users.noreply.github.com> Date: Thu, 24 Mar 2022 15:12:56 +0100 Subject: [PATCH] chore(C): add odd or even number (#719) Co-authored-by: LuigiAltamura --- algorithms/C/README.md | 1 + algorithms/C/maths/odd-or-even-number.c | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 algorithms/C/maths/odd-or-even-number.c diff --git a/algorithms/C/README.md b/algorithms/C/README.md index 6caf86ae..a1188256 100644 --- a/algorithms/C/README.md +++ b/algorithms/C/README.md @@ -34,6 +34,7 @@ - [Palindrome Number](maths/palindrome.c) - [Fibonacci Series](maths/fibonacci-series.c) +- [Odd or Even Number](maths/odd-or-even-number.c) ## Queues diff --git a/algorithms/C/maths/odd-or-even-number.c b/algorithms/C/maths/odd-or-even-number.c new file mode 100644 index 00000000..2cd3553b --- /dev/null +++ b/algorithms/C/maths/odd-or-even-number.c @@ -0,0 +1,32 @@ +/** + *This program checks if a number is odd or even. + * + * Odd numbers are whole numbers that cannot be divided exactly by 2. If the number is not divisible by 2 entirely, + * it'll leave a remainder 1. + * Even numbers are whole numbers that can be divided exactly by 2. If we divide the number by 2, it'll leave a remander 0. + * + * Complexity -> O(1) + * _______________________________ + * | INPUT | OUTPUT | + * | 2 | It's an even number! | + * | 1 | It's an odd number! | + * | 3 | It's an odd number! | + * _______________________________ +* */ + +#include + +int main() +{ + int n; + printf("Enter a number:\n"); + scanf("%d", &n); + + if(n % 2 == 0 ){ + printf("It's an even number!"); + }else{ + printf("It's an odd number!"); + } + + return 0; +} \ No newline at end of file