diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..d930726 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -4,4 +4,27 @@ 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() +{ + char alpha = 'a'; + + while (alpha <= 'z') + { + if (alpha == 'q' || alpha == 'e') + { + alpha++; + } + printf("%c", alpha); + alpha++; + if (alpha <= 'z') + { + printf(", "); + } + + } + return (0); +} + diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..e1c415e 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,22 @@ 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(int score) +{ + printf("Please input score: "); + scanf("%d", &score); + + if (score < 80) + { + printf("You are not eligible to be enrolled"); + } + else + { + printf("You are eligible to be enrolled"); + } + return (0); +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..e088b1c 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(int number) +{ + printf("Please input number: "); + scanf("%d", &number); + + if ((number % 2) == 0) + { + printf("Userinput is Even"); + } + else + { + printf("Userinput is odd"); + } + return (0); +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..475c393 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -11,4 +11,20 @@ How old are you?: 65 Output: Your name is David and you are 65 years old. -*/ \ No newline at end of file +*/ + + + +#include + +int main(char *name, int age) +{ + printf("Input name: "); + scanf("%s", &name); + printf("Input age: "); + scanf("%d", &age); + + printf("Your name is %s and you are %d years old", &name, age); + + return (0); +} diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..746284a 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,28 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ + +#include + +int square_number(int num); +int square_number(int num) +{ + int square; + + square = num * num; + + return (square); +} +int main() +{ + int a; + int b; + + a = square_number(-5); + b = square_number(6); + + printf("%d and %d", a, b); + return (0); +} + diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..eedc3ff 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,42 @@ /* Write a program in C to check a given number is even or odd using the function. -*/ \ No newline at end of file +*/ + +#include + +int even_odd(int num); +int even_odd(int num) +{ + if ((num % 2) == 0) + { + return (0); + } + else + { + return (1); + } +} +int main() +{ + int a; + int num; + + for (num = 0; num <= 10; num++) + { + a = even_odd(num); + if (a == 0) + { + printf("even"); + } + else + { + printf("odd"); + } + if (num < 10) + { + printf(", "); + } + } + return (0); +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..f481e8a 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,20 @@ 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 +*/ + +#include + +void print_ALPHA(char c); + +void print_ALPHA(char c) +{ + c = 'A'; + + while (c <= 'Z') + { + printf("%c", c); + c++; + } + printf("\n"); +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..7b2bcbf 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,21 @@ /*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 +*/ + +#include + +void print_alpha(char c); + +void print_ALPHA(char c) +{ + c = 'a'; + + while (c <= 'z') + { + printf("%c", c); + c++; + } + printf("\n"); +} + diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..052f182 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,32 @@ 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 +*/ + +#include + +void is_upper(char c); + +void is_upper(char c) +{ + + if (c >= 'a' && c <= 'z') + { + printf("%c is lowercase\n", c); + } + if (c >= 'A' && c <= 'Z') + { + printf("%c is uppercase\n", c); + } +} + +int main() +{ + + is_upper('C'); + is_upper('c'); + is_upper('Z'); + is_upper('q'); + + return (0); +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..f77ee53 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,30 @@ Write a function that computes the absolute value of an integer. Understand what an absolute value is, before attempting it. -*/ \ No newline at end of file +*/ + + +#include + +int abs(int num); + +int abs(int num) +{ + if (num < 0) + { + num = -(num); + } + return (num); +} + +int main() +{ + int a = 89; + int c = -98; + int b = abs(a); + int d = abs(c); + + printf("The absolute value of %d is %d\n", a, b); + printf("The absolute value of %d is %d\n", c, d); + return (0); +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..e1916b5 100644 --- a/TASKS/Task 011.c +++ b/TASKS/Task 011.c @@ -6,4 +6,26 @@ Output should look like this; 9 x 1 = 9 9 x 2 = 18 ... and so on till 12 -*/ \ No newline at end of file +*/ + +#include + +void ninetimes(); + +void ninetimes() +{ + int a; + int times; + + for (a = 0; a <= 12; a++) + { + times = 9 * a; + printf("9 x %d = %d\n", a, times); + } +} + +int main() +{ + ninetimes(); + return (0); +} diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..011a0e7 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,24 @@ /*Write your solution after the comment Write a function that adds two integers and prints the result. -*/ \ No newline at end of file +*/ + +#include + +int add(int a, int b); + +int add(int a, int b) +{ + int sum; + + sum = a + b; + return (sum); +} + +int main() +{ + int sum1 = add(5, 7); + int sum2 = add(8, 2); + printf("%d\n%d\n", sum1, sum2); + return (0); +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..0ead63f 100644 --- a/TASKS/Task 013.c +++ b/TASKS/Task 013.c @@ -3,4 +3,28 @@ Write a function that prints all natural numbers from n to 100, followed by a new line. That is n is your argument, it should print from any number passed as argument till 100. -*/ \ No newline at end of file +*/ + +#include + +void print_natural(int num); + +void print_natural(int num) +{ + while (num <= 100) + { + printf("%d", num); + if (num < 100) + { + printf(", "); + } + num++; + } +} + +int main() +{ + print_natural(70); + return (0); +} + diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..39b6832 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -6,4 +6,33 @@ Your output should look like this; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...up to 10 times -*/ \ No newline at end of file +*/ + +#include + +void one_to_fourteen(); + +void one_to_fourteen() +{ + int a = 0; + int b = 0; + + while (b <= 10) + { + for (a = 0; a <= 14; a++) + { + printf("%d", a); + if (a < 14) + { + printf(" "); + } + } + printf("\n"); + b++; + } +} + +int main() +{ + one_to_fourteen(); +} diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..2d6db27 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,44 @@ multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz. Your output should like this; 1 2 fizz 4 buzz fizz 7 8 fizz... and so on. -*/ \ No newline at end of file +*/ + +#include + +void fizzbuzz(); + +void fizzbuzz() +{ + int a = 1; + + for (a = 1; a <= 100; a++) + { + if ((a % 15) == 0) + { + printf("FizzBuzz "); + } + else if ((a % 5) == 0) + { + printf("Buzz "); + } + else if ((a % 3) == 0) + { + printf("Fizz "); + } + else + { + printf("%d", a); + } + + if (a < 100) + { + printf(" "); + } + } +} + +int main() +{ + fizzbuzz(); + return (0); +} diff --git a/TASKS/Task 016.c b/TASKS/Task 016.c index 8700bc0..f690c4f 100644 --- a/TASKS/Task 016.c +++ b/TASKS/Task 016.c @@ -8,4 +8,30 @@ Output: 720 // That is 1x2x3x4x5x6 = 720 -*/ \ No newline at end of file +*/ + + +#include + +int recursion_product(int a); + +int recursion_product(int a) +{ + if (a > 1) + { + return (a * recursion_product(a - 1)); + } + else + { + return (1); + } +} + +int main() +{ + int a = recursion_product(6); + + printf("%d", a); + return (0); +} + diff --git a/TASKS/Task 017.c b/TASKS/Task 017.c index f5ef778..b89904c 100644 --- a/TASKS/Task 017.c +++ b/TASKS/Task 017.c @@ -8,4 +8,29 @@ Output: 21 // That is; 1+2+3+4+5+6 = 21 -*/ \ No newline at end of file +*/ + + +#include + +int recursion_sum(int a); + +int recursion_sum(int a) +{ + if (a > 1) + { + return (a + recursion_sum(a - 1)); + } + else + { + return (1); + } +} + +int main() +{ + int a = recursion_sum(6); + + printf("%d", a); + return (0); +} diff --git a/TASKS/Task 018.c b/TASKS/Task 018.c index 147ff9a..08656dd 100644 --- a/TASKS/Task 018.c +++ b/TASKS/Task 018.c @@ -2,4 +2,28 @@ Write a function that returns the value of x raised to the power of y. functionName(int x, int y); -*/ \ No newline at end of file +*/ + +#include + +int pow(int a, int b); + +int pow(int a, int b) +{ + if (b > 0) + { + return (a * pow(a, b - 1)); + } + else + { + return (1); + } +} + +int main() +{ + int a = pow(2, 5); + + printf("%d", a); + return (0); +} diff --git a/TASKS/Task 019.c b/TASKS/Task 019.c index 5cc5874..38fbb9f 100644 --- a/TASKS/Task 019.c +++ b/TASKS/Task 019.c @@ -1,4 +1,6 @@ /* Write a function to convert temperature from Celsius to Fahrenheit and vice versa. -*/ \ No newline at end of file +*/ + + diff --git a/TASKS/Task-21-Pointers-Quiz.md b/TASKS/Task-21-Pointers-Quiz.md index 9f783c2..5fc5b72 100644 --- a/TASKS/Task-21-Pointers-Quiz.md +++ b/TASKS/Task-21-Pointers-Quiz.md @@ -1,17 +1,17 @@ -What is the purpose of pointers in C programming languages? +What is the purpose of pointers in C programming languages? Pointers are used to access the memory address of a variable, a pointer can also be used to manipulate what is saved in that particular memory address. -What is the difference between a pointer and a regular variable in C programming languages? +What is the difference between a pointer and a regular variable in C programming languages? A regular variable gives the value of something but a pointer give the memory address of something -How do you declare a pointer in C programming languages? +How do you declare a pointer in C programming languages? data-type (*)pointer_name; -How do you access the value stored at the memory address pointed by a pointer in C programming languages? +How do you access the value stored at the memory address pointed by a pointer in C programming languages? using the dereference symbol * -What is a null pointer in C programming languages? +What is a null pointer in C programming languages? a pointer that contains a memory address of 0 "\0" -How do you declare pointers to pointers in C programming languages? +How do you declare pointers to pointers in C programming languages? if for instance we what to point to an int we say int *ptr = 8; -What is the relationship between pointers and arrays in C programming languages? +What is the relationship between pointers and arrays in C programming languages? a pointer can be used to change the values in an array -What is dynamic memory allocation in C programming languages and how is it achieved using pointers? +What is dynamic memory allocation in C programming languages and how is it achieved using pointers? this is the method of creating memory for a specific purpose, memory created dynamically are on the heap -How do you deallocate dynamically allocated memory in C programming languages? \ No newline at end of file +How do you deallocate dynamically allocated memory in C programming languages? you use the free() function diff --git a/TASKS/Task-22.c b/TASKS/Task-22.c index 8cd01c4..6cedd16 100644 --- a/TASKS/Task-22.c +++ b/TASKS/Task-22.c @@ -2,4 +2,21 @@ Create a program that declares a pointer to an integer, assigns an address to it, and outputs the value stored at the memory address pointed by the pointer. -*/ \ No newline at end of file +*/ + +#include + +int main() +{ + int a; + int *ptr; + + ptr = &a; + + *ptr = 89; + + printf("%d %d", a, *ptr); + + return (0); + +} diff --git a/TASKS/Task-23.c b/TASKS/Task-23.c index dfddb16..b76fb97 100644 --- a/TASKS/Task-23.c +++ b/TASKS/Task-23.c @@ -1,4 +1,4 @@ /* Create a program that uses pointers to find the maximum value stored in an array. -*/ \ No newline at end of file +*/ diff --git a/TASKS/Task-24.c b/TASKS/Task-24.c index 79d1c16..82e943b 100644 --- a/TASKS/Task-24.c +++ b/TASKS/Task-24.c @@ -1,4 +1,4 @@ /* Create a program that demonstrates the use of pointers to pass information between functions. -*/ \ No newline at end of file +*/ diff --git a/TASKS/Task-25.c b/TASKS/Task-25.c index e2aa2a5..0ef27ea 100644 --- a/TASKS/Task-25.c +++ b/TASKS/Task-25.c @@ -1,3 +1,19 @@ /* Declare two integer variables and swap their values using a pointer. -*/ \ No newline at end of file +*/ +#include + +int main() +{ + int a = 6; + int b = 2; + int *temp; + + *temp = a; + a = b; + b = *temp; + + printf("%d %d", a, b); + + return (0); +}