diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..150c81f 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -4,4 +4,18 @@ Write a program that prints the alphabet in lowercase, followed by a new line. Print all the letters except q and e use printf -*/ \ No newline at end of file +*/ +#include + +int main(void) +{ + char i; + + for (i = 'a'; i <= 'z'; i++) + { + if (i == 'q' || i == 'e') + continue; + printf("%c\n", i); + } + return (0); +} diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..85104b6 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,28 @@ Write a program that asks and reads the score of a user If the score is less than 80, display to the user that they are not elgible to be enrolled. If the score is greater than or equal 80, they can be enrolled. -*/ \ No newline at end of file +*/ +#include + +int main(void) +{ + int score; + int valid_input = 0; + while (valid_input == 0) + { + printf("input your score: \n"); + valid_input = scanf("%d", &score); + if (valid_input == 0) + { + printf("Invalid input. Please enter a number.\n"); + scanf("%*s"); + } + } + if (score < 80) + printf("you are not eligible for this course\n"); + + if (score >= 80) + printf("congratulations, you can enrol for this course\n"); + + return (0); +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..7fc1c34 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,22 @@ If the number is zero, display 'This is zero' NOTE: 'userInput' should be the number entered by the user. -*/ \ No newline at end of file +*/ +#include + +int main(void) +{ + int userInput; + + printf("input a number\n"); + scanf("%d\n", &userInput); + + if (userInput == 0) + printf("You entered zero\n"); + else if (userInput % 2 == 0) + printf("%d is even\n", userInput); + else + printf("%d is odd\n", userInput); + + return (0); +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..31ec5fc 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -11,4 +11,27 @@ How old are you?: 65 Output: Your name is David and you are 65 years old. -*/ \ No newline at end of file +*/ + +/** + * main - checks code + * Return: zero + */ +#include +#include + +int main(void) +{ + char name[50]; + int age; + + printf("Please enter your name: \n"); + scanf("%s \n", name); + + printf("input your age: \n"); + scanf("%d \n", &age); + + printf("Your name is %s and you are %d years old\n", name, age); + + return (0); +} diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..3c2e280 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,30 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ + +/** + * square - prints square of a number + * @num: number to square + * Return: square + */ +#include +int square(int num) +{ + return (num * num); +} +/** + * main - checks code + * @num: number + * Return: zero + */ +int main() +{ + int num; + + num = 2; + printf("square of %d is %d\n", num, square(num)); + + return (0); +} + diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..8af8a6a 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,38 @@ /* Write a program in C to check a given number is even or odd using the function. -*/ \ No newline at end of file +*/ +#include + +/** + * checker - checks for even or odd number + * @num: number to check + * Return: 1 for odd number, 0 for even number + */ + +int checker(int num) +{ + if (num % 2 == 0) + return (0); + else if (num % 2 == 1) + return (1); +} + +/** + * main - checks code + * Return: 0 + */ +int main(void) +{ + int num; + printf("Enter a number: \n"); + scanf("%d", &num); + + int result = checker(num); + if (result == 0) + printf("%d is even\n", num); + else + printf("%d is odd\n", num); + + return (0); +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..2692b0d 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,30 @@ write your solution after the comment Write a function that prints the alphabet, in uppercase, followed by a new line. -*/ \ No newline at end of file +*/ + +/** + * uppercase - prints alphabets in uppercase + * @c: characters + * + */ +#include + +void uppercase() +{ + char c; + + for (char c ='A'; c <= 'Z'; c++) + printf("%c\n", c); +} + +/** + * main - checks code + * Return: 0 + */ + +int main(void) +{ + uppercase(); + return (0); +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..cc40999 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,30 @@ /*write your solution after the comment Write a function that prints the alphabet, in lowercase followed by a new line. -*/ \ No newline at end of file +*/ + +/** + * lowercase - prints alphabets in lowercase + * @c: characters + * + */ +#include + +void lowercase() +{ + char c; + + for (char c ='a'; c <= 'z'; c++) + printf("%c\n", c); +} + +/** + * main - checks code + * Return: 0 + */ + +int main(void) +{ + lowercase(); + return (0); +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..9968791 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,4 @@ Write a function that checks for lowercase character. That is, when passed in an arguments, it checks if the argument is lowercase or uppercase. -*/ \ No newline at end of file +*/ diff --git a/TASKS/task001 b/TASKS/task001 new file mode 100755 index 0000000..5e78552 Binary files /dev/null and b/TASKS/task001 differ diff --git a/TASKS/task002 b/TASKS/task002 new file mode 100755 index 0000000..554a704 Binary files /dev/null and b/TASKS/task002 differ diff --git a/TASKS/task003 b/TASKS/task003 new file mode 100755 index 0000000..341b3e0 Binary files /dev/null and b/TASKS/task003 differ diff --git a/TASKS/task004 b/TASKS/task004 new file mode 100755 index 0000000..a9504fe Binary files /dev/null and b/TASKS/task004 differ diff --git a/TASKS/task005 b/TASKS/task005 new file mode 100755 index 0000000..64bc985 Binary files /dev/null and b/TASKS/task005 differ diff --git a/TASKS/task006 b/TASKS/task006 new file mode 100755 index 0000000..006abd7 Binary files /dev/null and b/TASKS/task006 differ diff --git a/TASKS/task007 b/TASKS/task007 new file mode 100755 index 0000000..35dcb8d Binary files /dev/null and b/TASKS/task007 differ diff --git a/TASKS/task008 b/TASKS/task008 new file mode 100755 index 0000000..d45eb6f Binary files /dev/null and b/TASKS/task008 differ