diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..6451459 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -4,4 +4,19 @@ 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 small; + + for (small = 'a'; small <= 'z'; small++) + { + if (small != 'e' && small != 'q') + printf("%c, \n", small); + } + printf('\n'); + return 0; +} diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..6fef092 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,26 @@ 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; + + printf("Please enter your score:"); + scanf("%d", &score); + + if (score < 80) + { + printf("Sorry, you are not eligible to be enrolled,try again"); + } + else if (score >= 80) + { + printf("Congratulations, you have been enrolled); + } + printf('\n'); + return 0; +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..1edd699 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,29 @@ 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 your number: "); + scanf("%d", &Number); + + if (Number == 0) + { + printf("This is zero"); + } + else if (Number % 2 == 0) + { + printf("userInput is even"); + } + else if (Number % 2 != 0) + { + printf("userInput is odd"); + } + printf('\n'); + return 0; +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..f868473 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -11,4 +11,22 @@ 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[30]; + int age; + + printf("What is your Name: \n"); + scanf("%s", &name); + printf("How old are you?: \n"); + scanf("%d", &age); + + printf("Your name is %s and you are %d years old", name, age); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..b9c274e 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,26 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ + +#include + +int squareNum(int num) +{ + return (num * num); +} + +int main() +{ + int num; + int n; + + printf("Input a whole number: "\n); + scanf("%d", &num); + + n = squareNum(num); + printf("The square of %d is: %d", num, n); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..0b554c0 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,32 @@ /* 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 EvenOrOdd(int num) +{ + if(num % 2 == 0) + { + printf("The number s an even number"); + } + else + { + printf("The number is an odd number"); + } +} + +int main() +{ + int num; + int n; + + printf("Please input a whole number: "); + scanf("%d", &num); + + n = EvenOrOdd(num); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..5957a51 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,23 @@ 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 + +char upper(char alpha) +{ + for(alpha = 'A'; alpha <= 'Z'; alpha++) + printf("%c, \n", alpha); +} + +int main() +{ + char alpha; + char big; + + big = upper(alpha); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..d031b97 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,24 @@ -/*write your solution after the comment -Write a function that prints the alphabet, in lowercase +/* +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 + +char lower(char alpha) +{ + for(alpha = 'a'; alpha <= 'z'; alpha++) + printf("%c, \n", alpha); +} + +int main() +{ + char alpha; + char small; + + small = lower(alpha); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..7ef5e91 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,36 @@ 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 + +char lowerOrUpper(char alpha) +{ + if(alpha >= 'A' && alpha <= 'Z') + { + printf("This is an uppercase character"); + } + else if(alpha >= 'a' && alpha <= 'z'); + { + printf("This is a lowercase character"); + } + else + { + printf("This is not a character"); + } +} + +int main() +{ + char alpha; + char x; + + printf("Please input a character: "); + scanf("%c", &alpha); + + x = lowerOrUpper(alpha); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..ce17fe9 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,33 @@ 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 absValue(int val) +{ + if(val < 0) + { + val = (-1) * val; + printf("The absolute value is: %d ", val); + } + else + { + printf("the absolute value is %d", val); + } +} + +int main() +{ + int val; + int x; + + printf("please enter a number: "); + scanf("%d", &val); + + x = absval(val); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..5e4fd50 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 + +int timesTable(int num) +{ + int x; + for(x = 0; x <= 12; x++) + { + printf("%d * %d = %d \n", num, x, (num * x)); + } +} + +int main() +{ + int num = 9; + int n; + + n = timesTable(num); + printf("Times Table of 9); + + printf('\n'); + return 0; diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..c1edc43 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,27 @@ /*Write your solution after the comment Write a function that adds two integers and prints the result. -*/ \ No newline at end of file +*/ + +int add(int num, int num2) +{ + int sum = num + num2; + printf("Therefore, %d + %d = %d \n", num, num2, sum); +} + +int main() +{ + int first; + int second; + int n; + + printf("Please enter the first Integer: "); + scanf("%d", &first); + printf("Please enter the second Integer: "); + scanf("%d", &second); + + n = add(first, second); + + printf('\n'); + return 0; +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..da17177 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 + +int printNaturalNum(int num, int N) +{ + for(num = N; num <= 100; num++) + printf("%d\n", num); +} + +int main() +{ + int i = 100; + int n; + int x; + + printf("Enter your N Number: "); + scanf("%d", &n); + + printf("Your Natural numbers from %d to %d: \n", n, i); + x = printNaturalNum(i, n); + + printf("\n"); + return 0; +} diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..377d644 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -6,4 +6,24 @@ 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 printTenTimes() +{ + int n, num; + + for (n = 1; n <= 10; n++) + { + for (num = 0; num <= 13; num++) + { + printf("%d\t", num); + } + printf("\n"); + } +} + +int main() +{ + printTenTimes(); +} diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..9823c49 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,33 @@ 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 + +int main(void) +{ + int i; + + for (i = 1; i <= 100; i++) + { + if ((i % 3) == 0 && (i % 5) == 0) + { + printf("FizzBuzz\t"); + } + else if ((i % 3) == 0) + { + printf("Fizz\t"); + } + else if ((i % 5) == 0) + { + printf("Buzz\t"); + } + else + { + printf("%d\t", i); + } + } + printf("\n"); + return 0; +} diff --git a/TASKS/Task 016.c b/TASKS/Task 016.c index 8700bc0..c7f385a 100644 --- a/TASKS/Task 016.c +++ b/TASKS/Task 016.c @@ -8,4 +8,31 @@ Output: 720 // That is 1x2x3x4x5x6 = 720 -*/ \ No newline at end of file +*/ + +#include + +int timesNumbers(int n) +{ + int product = 1, count = 0; + + for (int i = 1; i <= n; i++) + { + product = product * i; + count++; + } + return product; +} + +int main() +{ + int num; + + printf("Please input an integer: "); + scanf("%d", &num); + + printf("The product of numbers from 1 to %d is %d", num, timesNumbers(num)); + + printf("\n"); + return 0; +} diff --git a/TASKS/Task 017.c b/TASKS/Task 017.c index f5ef778..3d42804 100644 --- a/TASKS/Task 017.c +++ b/TASKS/Task 017.c @@ -8,4 +8,30 @@ Output: 21 // That is; 1+2+3+4+5+6 = 21 -*/ \ No newline at end of file +*/ + +#include + +int addNumbers(int n) +{ + int sum = 0; + + for (int i = 1; i <= n; i++) + { + sum += i; + } + return sum; +} + +int main() +{ + int num; + + printf("Please input an integer: "); + scanf("%d", &num); + + printf("The sum of numbers from 1 to %d is %d", num, addNumbers(num)); + + printf("\n"); + return 0; +} diff --git a/TASKS/Task 018.c b/TASKS/Task 018.c index 147ff9a..7be20f5 100644 --- a/TASKS/Task 018.c +++ b/TASKS/Task 018.c @@ -2,4 +2,32 @@ 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 raise_to_power(int x, int y) +{ + int power = 1; + int i; + + for (i = 1; i <= y; i++) + { + power = power * x; + } + return power; +} + +int main() +{ + int x, y; + + printf("Please input base x number: "); + scanf("%d", &x); + printf("Please input exponential y number: "); + scanf("%d", &y); + + printf("%d ^ %d = %d", x, y, raise_to_power(x,y)); + + printf("\n"); + return 0; +} diff --git a/TASKS/Task12 b/TASKS/Task12 new file mode 100755 index 0000000..bad037c Binary files /dev/null and b/TASKS/Task12 differ diff --git a/TASKS/Task13 b/TASKS/Task13 new file mode 100755 index 0000000..c1fe0a9 Binary files /dev/null and b/TASKS/Task13 differ diff --git a/TASKS/Task14 b/TASKS/Task14 new file mode 100755 index 0000000..1ee41c2 Binary files /dev/null and b/TASKS/Task14 differ diff --git a/TASKS/Task15 b/TASKS/Task15 new file mode 100755 index 0000000..2588244 Binary files /dev/null and b/TASKS/Task15 differ diff --git a/TASKS/Task16 b/TASKS/Task16 new file mode 100755 index 0000000..c34727b Binary files /dev/null and b/TASKS/Task16 differ diff --git a/TASKS/Task17 b/TASKS/Task17 new file mode 100755 index 0000000..52e7cd4 Binary files /dev/null and b/TASKS/Task17 differ diff --git a/TASKS/Task18 b/TASKS/Task18 new file mode 100755 index 0000000..628b353 Binary files /dev/null and b/TASKS/Task18 differ