Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tackled all the Challenges 1, 2, 3 #144

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions john-otienoh/fizz-buzz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
/**
* main - Entry point of the function
* Program that prints the numbers from 1 to 100.
* For multiples of 3, print Fizz;
* For multiples of 5, print Buzz;
* For numbers that are multiples of both 3 and 5, print FizzBuzz.
* Return: Always 0(success)
*/
int main(void)
{
int i;

for (i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
printf(" Fizzbuzz");
else if (i % 3 == 0)
printf(" Fizz");
else if (i % 5 == 0)
printf(" Buzz");
else
printf(" %d", i);
}
printf("\n");
return (0);
}
22 changes: 22 additions & 0 deletions john-otienoh/fizz_buzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python3

def fizz_buzz():
"""
Program that prints the numbers from 1 to 100.
For multiples of 3, print Fizz;
For multiples of 5, print Buzz;
For numbers that are multiples of both 3 and 5, print FizzBuzz
"""
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("Fizzbuzz ", end="")
elif i % 3 == 0:
print("Fizz ", end="")
elif i % 5 == 0:
print("Buzz ", end="")
else:
print(f"{i} ", end="")
print("\n")

if __name__ == "__main__":
fizz_buzz()
31 changes: 31 additions & 0 deletions john-otienoh/power_of_two.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
char *power_of_two(int n);
/**
* main - Entry point of the function
* Return: Always 0(success)
*/
int main(void)
{
int n;
printf("Enter a number: ");
scanf("%d", &n);

(power_of_two(n) == "True") ? printf("True\n") : printf("False\n");
return (0);
}

/**
* power_of_two - Program that takes an integer as input
* @n: Integer
* Return: true if the input is a power of two else false.
*/

char *power_of_two(int n)
{
while (n % 2 == 0)
{
n = n / 2;
if (n == 1)
return ("True");
}
}
13 changes: 13 additions & 0 deletions john-otienoh/power_of_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python3

def power_of_two(n):
"""
program that takes an integer as input
returns true if the input is a power of two else false.
"""
return False if n <= 0 else (n & (n - 1) ) == 0


if __name__ == "__main__":
print(power_of_two(int(input("Enter Number: "))))

38 changes: 38 additions & 0 deletions john-otienoh/reverse_integer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>

int reverse_integer(int n);
/**
* main - Entry point of the function
* Program that takes an integer as input and return/prints an integer with reversed digit ordering.
* Return: Always 0(success)
*/
int main(void)
{
int n, reversed_num = 0;
printf("Enter Digit: ");
scanf("%d", &n);

if (n < 0)
reversed_num = reverse_integer(abs(n)) * -1;
else
reversed_num = reverse_integer(n);

printf("The reverse is %d\n", reversed_num);
}

/**
* reverse_integer - Program that takes an integer as input and return/prints an integer with reversed digit ordering.
* @n: The integer to be reversed
* Return: The reversed integer
*/
int reverse_integer(int n)
{
int reverse = 0;
while (n > 0)
{
reverse = reverse * 10 + n % 10;
n /= 10;
}
return (reverse);
}
16 changes: 16 additions & 0 deletions john-otienoh/reverse_integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/python3

def reverse_integer(num):
"""
Function that takes an integer as input and return/prints an integer with reversed digit ordering.
"""
reverse = 0
while num > 0:
reverse = reverse * 10 + num % 10
num = num // 10
return reverse

if __name__ == "__main__":
n = int(input("Enter a number: "))
t = "The reverse is "
print(f"{t}{reverse_integer(abs(n)) * -1}") if n < 0 else print(f"{t}{reverse_integer(n)}")