chore(C): add odd or even number (#719)
Co-authored-by: LuigiAltamura <luigi.altamura@mail.polimi.it>pull/732/head
parent
f35e35ef5c
commit
ec7c098897
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
- [Palindrome Number](maths/palindrome.c)
|
- [Palindrome Number](maths/palindrome.c)
|
||||||
- [Fibonacci Series](maths/fibonacci-series.c)
|
- [Fibonacci Series](maths/fibonacci-series.c)
|
||||||
|
- [Odd or Even Number](maths/odd-or-even-number.c)
|
||||||
|
|
||||||
## Queues
|
## Queues
|
||||||
|
|
||||||
|
|
|
@ -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 <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue