From e653f1a019afd3790e1d39ed1308c40c7277176a Mon Sep 17 00:00:00 2001 From: funxal Date: Thu, 19 Jan 2023 16:56:18 +0000 Subject: [PATCH 1/3] this task --- TASKS/Task 001.c | 20 +++++++++++++++++++- TASKS/Task 002.c | 20 +++++++++++++++++++- TASKS/Task 003.c | 20 +++++++++++++++++++- TASKS/Task 004.c | 19 +++++++++++++++++-- 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..8f6ca88 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -4,4 +4,22 @@ 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 alp; + + for (alp = 'a'; alp <= 'z'; alp++) + { + if (alp == 'e' || alp == 'q') + { + continue; + } + printf("%c", alp); + } + printf("\n"); + return (0); +} diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..2ac561b 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(void) +{ + int score; + + printf("Please enter your score "); + scanf("%d", &score); + + if (score == 80 || score > 80) + { + printf("You are eligible to enroll for this program\n"); + } + else + printf("You are not eligible to enroll for this program\n"); + return (0); +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..540831b 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("Please enter your magic number "); + scanf("%d", &userInput); + + if ((userInput % 2) == 0) + printf("Your magic number is even!\n"); + else if ((userInput % 2) == 1) + printf("Your magic number is odd!\n"); + else + printf("This is zero\n"); + return (0); +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..2b25a28 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -1,5 +1,5 @@ /* Write your program after the comment -Write a program that asks and reads the following input from a use; +Write a program that asks and reads the following input from a user; Your name Your age and then displays; Your name is 'name' and you are 'age' years old. @@ -11,4 +11,19 @@ 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(void) +{ + char name[10]; + int age, y; + + printf("What is your name?\nHow old are you? \n"); + scanf("%s %d", name, &age); + + printf("Your name is %s and you are %d years old.\n", name, age); + return (0); +} + From a13f33c2085e97831bee4aa4a33b5dcd80e69cb1 Mon Sep 17 00:00:00 2001 From: funxal Date: Thu, 19 Jan 2023 17:45:00 +0000 Subject: [PATCH 2/3] fixed --- TASKS/Task 003.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 540831b..affda81 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -17,11 +17,14 @@ int main(void) printf("Please enter your magic number "); scanf("%d", &userInput); - if ((userInput % 2) == 0) - printf("Your magic number is even!\n"); - else if ((userInput % 2) == 1) + if ((userInput % 2) == 1) printf("Your magic number is odd!\n"); - else + /*else if ((userInput % 2) == 1) + printf("Your magic number is odd!\n"); + */ + else if (userInput == 0) printf("This is zero\n"); + else + printf("Your magic number is even!\n"); return (0); } From 072373bdfc1829fb01ff70f1b473c322ba11bb2a Mon Sep 17 00:00:00 2001 From: funxal Date: Wed, 25 Jan 2023 14:11:26 +0000 Subject: [PATCH 3/3] done --- TASKS/Task 004.c | 15 ++++++++------- TASKS/Task 005.c | 26 +++++++++++++++++++++++++- TASKS/Task 006.c | 24 +++++++++++++++++++++++- TASKS/Task 007.c | 24 +++++++++++++++++++++++- TASKS/Task 008.c | 29 ++++++++++++++++++++++++++--- TASKS/Task 009.c | 30 +++++++++++++++++++++++++++++- TASKS/Task 010.c | 43 ++++++++++++++++++++++++++++++++++++++++++- TASKS/Task 011.c | 25 ++++++++++++++++++++++++- TASKS/Task 012.c | 29 ++++++++++++++++++++++++++++- TASKS/Task 013.c | 42 +++++++++++++++++++++++++++++++++++++++++- TASKS/Task 014.c | 26 +++++++++++++++++++++++++- TASKS/Task 015.c | 36 +++++++++++++++++++++++++++++++++++- 12 files changed, 329 insertions(+), 20 deletions(-) diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 2b25a28..0dcc3f1 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -14,16 +14,17 @@ Your name is David and you are 65 years old. */ #include - int main(void) { - char name[10]; - int age, y; + char name[50]; + int age; - printf("What is your name?\nHow old are you? \n"); - scanf("%s %d", name, &age); + printf("What is your name? "); + scanf("%s", name); + printf("How old are you? "); + scanf("%d", &age); - printf("Your name is %s and you are %d years old.\n", name, age); + printf("Your name is %s and you are %d years old!", name, age); + putchar('\n'); return (0); } - diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..0db3834 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 + +unsigned int sq(int s); +unsigned int sq(int s) +{ + unsigned si; + + si = s * s; + printf("%d\n", si); + return (si); +} + +int main(void) +{ + int a; + + a = 16; + sq(a); + sq(3); + sq(144); + + return (0); +} diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..8c920d1 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,26 @@ /* Write a program in C to check a given number is even or odd using the function. -*/ \ No newline at end of file +*/ + +#include + +void check(int c); +int main(void) +{ + int a; + + printf("Enter any number: "); + scanf("%d", &a); + + check(a); + return (0); +} + +void check(int c) +{ + if ((c % 2) != 0) + printf("This number is an odd number\n"); + else + printf("This number is a even number\n"); +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..af73577 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,26 @@ 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 alp(); +int main(void) +{ + alp(); + return (0); +} + +void alp() +{ + int p; + p = 65; + + while (p <= 90) + { + putchar(p); + p++; + } + putchar('\n'); +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..d8e94b8 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,27 @@ -/*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 + +void alp(); +int main(void) +{ + alp(); + return (0); +} + +void alp() +{ + int p; + p = 'a'; + + while (p <= 'z') + { + putchar(p); + p++; + } + putchar('\n'); +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..7bdff21 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 check(char a); +int main(void) +{ + char r; + + printf("Enter any letter: "); + scanf("%c", &r); + + check(r); + check('r'); + check('J'); + return (0); +} + +void check(char a) +{ + if (a >= 'a' && a <= 'z') + { + printf("%c is lower\n", a); + } + else if (a >= 'A' && a <='Z') + { + printf("%c is upper\n", a); + } +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..459cef1 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,45 @@ 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 absolute(int a); +int main(void) +{ + int ab; + int a; + + printf("Enter any digit "); + scanf("%i", &ab); + + printf("The abolute value of the digit you entered is %d\n", absolute(ab)); + a = absolute(8); + printf("%i", a); + putchar('\n'); + a = absolute(190); + printf("%i", a); + putchar('\n'); + a = absolute(0); + printf("%i", a); + putchar('\n'); + a = absolute(-2); + printf("%i", a); + putchar('\n'); + return (0); +} + +int absolute(int a) +{ + if (a < 0) + { + return (a * (-1)); + } + else if (a >= 0) + { + return (a); + } + putchar('\n'); + return (a); +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..2202695 100644 --- a/TASKS/Task 011.c +++ b/TASKS/Task 011.c @@ -6,4 +6,27 @@ 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 times(int t); +int main(void) +{ + times(9); + return (0); +} + +int times(int t) +{ + int y, m; + + y = 0; + while (y < 13) + { + m = (t * y); + printf("%i x %i = %i\n", t, y, m); + y++; + } +/* return ();*/ +} diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..e24d48b 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,31 @@ /*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 main(void) +{ + int r, y, m; + + m = r + y; + printf("Enter any two digits you would like to add "); + scanf("%d%d", &r, &y); + + m = r + y; + printf("The sum of the digits you entered is %d\n", m); + m = add(5, 10); + printf("%d\n", m); + m = add(-16, 20); + printf("%d\n", m); + return (0); +} +int add(int a, int b) +{ + int t; + + t = a + b; + return (t); +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..4c39310 100644 --- a/TASKS/Task 013.c +++ b/TASKS/Task 013.c @@ -3,4 +3,44 @@ 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 natural(int a); +int main(void) +{ + natural(10); + natural(100); + natural(101); + natural(150); + natural(0); + natural(-10); + natural(-110); + return (0); +} + +void natural(int a) +{ + if (a > 100) + { + while (a >= 100) + { + printf("%d", a); + printf(" "); + a--; + } + } + else if (a < 100) + { + while (a <= 100) + { + printf("%d", a); + printf(" "); + a++; + } + } + else + printf("%d", a); + printf("\n"); +} diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..d1e34af 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -6,4 +6,28 @@ 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 up_to_14(); +int main(void) +{ + up_to_14(10); + return (0); +} + +void up_to_14() +{ + for (int i = 1; i <= 10; i++) + { + int e = 1; + while (e <= 14) + { + printf("%d", e); + putchar(' '); + e++; + } + putchar('\n'); + } +} diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..2aa17e3 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,38 @@ 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 fizz(); +int main(void) +{ + fizz(); + return (0); +} + +void fizz() +{ + int a; + + for (a = 1; a <= 100; a++) + { + if ((a % 3) == 0 && (a % 5) == 0) + { + printf("fizzbuzz"); + } + else if ((a % 3) == 0) + { + printf("fizz"); + } + else if ((a % 5) == 0) + { + printf("buzz"); + } + else + printf("%d", a); + putchar(' '); + } + putchar('\n'); +}