From 96b169161c3e7916240707db5695c27fad21a560 Mon Sep 17 00:00:00 2001 From: JCtech Date: Thu, 26 Jan 2023 20:34:40 +0100 Subject: [PATCH 01/25] Tasks done by Justice --- 06-conditional-statements.c | 41 ++++++++++++++++++++++++++++- 07-loops.c | 44 +++++++++++++++++++++++++++++++- 08-Ternary-Operator.c | 16 +++++++++++- 09-Nested-Loops.c | 28 +++++++++++++++++++- 10-Break-and-Continue.c | 2 +- 11-Switch-Statement.c | 51 ++++++++++++++++++++++++++++++++++++- 6 files changed, 176 insertions(+), 6 deletions(-) diff --git a/06-conditional-statements.c b/06-conditional-statements.c index b095295..8a8a073 100644 --- a/06-conditional-statements.c +++ b/06-conditional-statements.c @@ -17,6 +17,22 @@ Practice Program Check if a number is negative */ +#include + +int main() +{ + int n; + printf("Enter a number\n"); + scanf("%d", &n); + + if (n < 0) + { + printf("%d is a negative number\n", n); + } + + + + /* C if...else Statement @@ -42,6 +58,23 @@ Practice Program Check whether a number is odd or even */ + + int p; + printf("Enter a number\n"); + scanf("%d", &p); + + if (p % 2 == 0) + { + printf("%d is an even number\n", p); + } + + else + { + printf("%d is an odd number\n", p); + } +return (0); +} + /* C if...else Ladder The if...else statement executes two different codes depending @@ -70,4 +103,10 @@ else { Practice Program Program to relate two integers using ==, > or < symbol -*/ \ No newline at end of file + + +=*=*=*=*=*= Please explain this practice task =*=*=*=*=*=*= + + + +*/ diff --git a/07-loops.c b/07-loops.c index 72ea267..8d385de 100644 --- a/07-loops.c +++ b/07-loops.c @@ -33,6 +33,20 @@ Print Numbers 1 - 10 Calculate the sum */ +#include + +int main() +{ + int sum = 0; + + for ( int i = 1; i <= 10; ++i) + { + printf("%d ", i); + sum += i; + } + + printf("\nsum = %d\n", sum); + /* C while loop The syntax of the while loop is: @@ -51,6 +65,14 @@ Practice Program Print Numbers 1 - 10 */ +int n = 0; + + while (n < 10) + { + ++n; + printf("%d ", n); + } + /* do...while loop The do..while loop is similar to the while loop with one important @@ -72,4 +94,24 @@ How do...while loop works? Practice Program Ask for correct input continously -*/ \ No newline at end of file +*/ + + +int num; + printf("Enter a number from 1 to 3\n"); + scanf("%d", &num); + + do + { + printf("Enter the correct input\n"); + scanf("%d", &num); + } + while (num > 3); + + if (num < 3) + printf("%d is correct", num); + + +return (0); + +} diff --git a/08-Ternary-Operator.c b/08-Ternary-Operator.c index 6d968b6..4264d6b 100644 --- a/08-Ternary-Operator.c +++ b/08-Ternary-Operator.c @@ -16,4 +16,18 @@ Syntax condition ? value_if_true : value_if_false Ternary operator can also be nested -*/ \ No newline at end of file +*/ + +#include + +int main() +{ + int num; + + printf("Enter a number\n"); + scanf("%d",&num); + + num % 2 == 0 ? printf("%d is an even number", num) : printf("%d is an odd number", num); + +return (0); +} diff --git a/09-Nested-Loops.c b/09-Nested-Loops.c index 2b01945..b1fa34c 100644 --- a/09-Nested-Loops.c +++ b/09-Nested-Loops.c @@ -34,6 +34,32 @@ Practice Problem FizzBuzz */ + +#include + +int main(void) +{ + int i; + + for (i=1; i<=100; i++) + { + if (i%15 == 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); + } + + return 0; +} + + /* int n = 6;// variable declaration //printf("Enter the value of n :"); @@ -46,4 +72,4 @@ int n = 6;// variable declaration } printf("\n"); } -*/ \ No newline at end of file +*/ diff --git a/10-Break-and-Continue.c b/10-Break-and-Continue.c index 0cf3758..0bb8b9a 100644 --- a/10-Break-and-Continue.c +++ b/10-Break-and-Continue.c @@ -44,4 +44,4 @@ for (i = 0; i < 10; i++) { printf("%d\n", i); } -*/ \ No newline at end of file +*/ diff --git a/11-Switch-Statement.c b/11-Switch-Statement.c index 7015891..c9575b4 100644 --- a/11-Switch-Statement.c +++ b/11-Switch-Statement.c @@ -33,4 +33,53 @@ The default clause inside the switch statement is optional. Practice Program Create a calculator -*/ \ No newline at end of file +*/ + +#include + +int main() +{ + + double n1, n2, result; + char opp; + + + scanf("%c", &opp); + scanf("%lf %lf", &n1, &n2); + + /*if (opp != '*' && opp != '+' && opp != '%' && opp != '-') + { + printf("Enter a valid operator"); + scanf("%c", &opp); + }*/ + + + switch (opp) + { + case '+': + result = n1 + n2; + printf("%lf", result); + break; + + + case '-': + result = n1 - n2; + printf("%lf", result); + break; + + case '/': + result = n1 / n2; + printf("%lf", result); + break; + + case '*': + result = n1 * n2; + printf("%lf", result); + break; + + default: + printf("Enter a valid operator"); + } + +return (0); +} From 199f89d9f7df367c20728590141b287022e56d83 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:14:32 +0100 Subject: [PATCH 02/25] Update Task 001.c --- TASKS/Task 001.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..412c98f 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -4,4 +4,20 @@ 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() +{ + + + for ( char i = 'a'; i <= 'z' ; i++) + { + if (i != 'e' && i != 'q') + { + printf("%c\n", i); + } + } +return (0); +} From 15c680b2a60ea9fd3ac5755e79655a84f7344094 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:34:24 +0100 Subject: [PATCH 03/25] Update Task 002.c --- TASKS/Task 002.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..1e91ebe 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() +{ + int score; + + printf("Enter your score\n"); + scanf("%d", &score); + + if (score >= 80) + { + printf("You are eligible to enrole"); + } + else + { + printf("you are not eligible to enrole"); + } + + + return (0); +} From 36cd64b4ac560f83a8d87f93e517d152ea4589e4 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sun, 5 Feb 2023 20:44:37 +0100 Subject: [PATCH 04/25] Update Task 003.c --- TASKS/Task 003.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..b397eef 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,36 @@ 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 num; + +printf("Enter a number\n"); +scanf("%d", &num); + + if (num >= 1) + { + if (num % 2 == 0) + { + printf("%d is Odd number", num); + } + else + { + printf("%d is Even number", num); + } + } + else if (num == 0) + { + printf("This is zero"); + } + else + { + printf("\"Error!\" Enter a positive number"); + } + +return (0); +} From 7781db5604ad17a07f12d2082727cd1a526ae6be Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sun, 5 Feb 2023 22:35:18 +0100 Subject: [PATCH 05/25] Update Task 004.c --- TASKS/Task 004.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..679a679 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -11,4 +11,21 @@ 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 age[5], name[10]; + + printf("What is your name:\n"); + scanf("%s", &name); + printf("How old are you\n"); + scanf("%s", &age); + + printf("Your name is %s and you are %s years old.", name, age); + +return (0); +} From bb559aaa03c3a92d357bbaa41d02e275794bbe61 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 6 Feb 2023 01:43:43 +0100 Subject: [PATCH 06/25] Update Task 005.c --- TASKS/Task 005.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..89769dc 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,20 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ + +#include +#include + +int main() +{ + int x; + printf("Enter a number to find the square root\n"); + scanf("%d", &x); + + float res; + res = sqrt(x); + printf (" The square root of %d is: %.2f", x, res); + + return 0; +} From 66eccb13dccaa6749598686eb7185a65f32dcc17 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 6 Feb 2023 20:35:00 +0100 Subject: [PATCH 07/25] Update Task 006.c --- TASKS/Task 006.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..8d48298 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 +int checkEven(int a) +{ + + + if (a % 2 == 0) + { + printf("%d is an Even number", a); + } + else + { + printf("%d is an Odd number", a); + } +} +int main() +{ + int num; + printf("Enter a number\n"); + scanf("%d", &num); + + checkEven(num); From d1ab1cbcefb6c8bdcb742985192f0618a9f2ebb0 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:53:46 +0100 Subject: [PATCH 08/25] Update Task 007.c --- TASKS/Task 007.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..6813e00 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,21 @@ 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 upperAlpha() +{ + for (char i = 'A'; i <= 'Z'; ++i) + { + printf("%c\n", i); + } +} + +int main() +{ + upperAlpha(); + + return (0); +} From d34d87e54144a790306192ec569710b0b9e9f8d3 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:55:48 +0100 Subject: [PATCH 09/25] Update Task 008.c --- TASKS/Task 008.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..a7b4269 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 + +char upperAlpha() +{ + for (char i = 'a'; i <= 'z'; ++i) + { + printf("%c\n", i); + } +} + +int main() +{ + upperAlpha(); + + return (0); +} From f02d14688475350aca3aa537c91c5191e191228b Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 6 Feb 2023 23:19:21 +0100 Subject: [PATCH 10/25] Update Task 009.c --- TASKS/Task 009.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..8442036 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,30 @@ 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 checkCase(char b) +{ + if (b >= 'a' && b <= 'z') + { + printf("This is a lowercase character\n"); + } + else + { + printf("This is not a lowercase character\n"); + } +} + +int main() +{ + char s; + + printf("Enter a character\n"); + scanf("%c", &s); + + checkCase(s); + + return (0); +} From 96c7abbb0c7e1b8ccdba9ce5d15bb752f9814bd9 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 7 Feb 2023 00:30:27 +0100 Subject: [PATCH 11/25] Update Task 011.c --- TASKS/Task 011.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..d26246e 100644 --- a/TASKS/Task 011.c +++ b/TASKS/Task 011.c @@ -6,4 +6,19 @@ 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 nineTable() +{ + for (int i = 0; i <= 12; ++i) + { + printf("9 x %d = %d\n", i, 9 * i); + } +} + +int main() +{ + nineTable(); +} From ac00833f20ebf38c8e5ee532ff4f32a3ecc0135c Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:30:03 +0100 Subject: [PATCH 12/25] Update Task 012.c --- TASKS/Task 012.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..2104e9f 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,30 @@ /*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 absNum(int n) +{ + int abs; + if (n < 0) + { + abs = n - n - n; + printf("The absolute of %d is %d", n, abs); + } + else + { + printf("The absolute of %d is %d", n, n); + } +} + +int main() +{ + int num; + printf("Enter a number:\n"); + scanf("%d", &num); + + absNum(num); + + return (0); +} From 414364f1289bbe297103330de4389e24bb5067a2 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:31:40 +0100 Subject: [PATCH 13/25] Update Task 010.c --- TASKS/Task 010.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..b48650c 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 absNum(int n) +{ + int abs; + if (n < 0) + { + abs = n - n - n; + printf("The absolute of %d is %d", n, abs); + } + else + { + printf("The absolute of %d is %d", n, n); + } +} + +int main() +{ + int num; + printf("Enter a number:\n"); + scanf("%d", &num); + + absNum(num); + + return (0); +} From 153ea76ba4f6e8c21a82c62cbc6b1dad672c58f5 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:32:32 +0100 Subject: [PATCH 14/25] Update Task 012.c --- TASKS/Task 012.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 2104e9f..1418b9b 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -3,28 +3,3 @@ Write a function that adds two integers and prints the result. */ -#include -int absNum(int n) -{ - int abs; - if (n < 0) - { - abs = n - n - n; - printf("The absolute of %d is %d", n, abs); - } - else - { - printf("The absolute of %d is %d", n, n); - } -} - -int main() -{ - int num; - printf("Enter a number:\n"); - scanf("%d", &num); - - absNum(num); - - return (0); -} From 19c850c2af46a1b2269aa3f7614f61a704921acb Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 7 Feb 2023 19:21:05 +0100 Subject: [PATCH 15/25] Update Task 012.c --- TASKS/Task 012.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 1418b9b..f82cbc3 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -3,3 +3,20 @@ Write a function that adds two integers and prints the result. */ +#include + +int add(int a, int b) +{ + int sum; + sum = a + b; + printf("%d + %d = %d\n", a, b, sum); +} + +int main() +{ + int n1, n2; + printf("Enter two numbers to add\n"); + scanf("%d \n %d", &n1, &n2); + + add(n1, n2); +} From 806e09db56264f78511c9e063f57485ba86c8eb2 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:18:41 +0100 Subject: [PATCH 16/25] Update Task 013.c --- TASKS/Task 013.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..21e895c 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 natNum(int n) +{ + for (int i = 0; i <= 100; ++i) + { + if (n <= i) + { + printf("%d\t", i); + } + } +} + +int main() +{ + int num; + printf("Enter a number to count till 100\n"); + scanf("%d", &num); + + natNum(num); + + return (0); +} From 8cd318329e6f2a7ee4d444de20a023d38895d106 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:36:26 +0100 Subject: [PATCH 17/25] Update Task 014.c --- TASKS/Task 014.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..8e60292 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -6,4 +6,18 @@ 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 tenTimesNum() +{ + + for (int i = 0; i < 10; ++i)// why does < print up to 10 + { + for (int n = 0; n <= 14; ++n)// why does only < not print up to 14 + { + printf("%d ", n); + } + printf("\n"); + } From 6b6a8a1e065ee762957a702187a332cfe528f8c9 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:51:25 +0100 Subject: [PATCH 18/25] Update Task 014.c --- TASKS/Task 014.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index 8e60292..375c1e1 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -21,3 +21,9 @@ void tenTimesNum() } printf("\n"); } + +int main() +{ + tenTimesNum(); +return(0); +} From 07b4ff43e5b0fbc7b8a9852a105c6e419d347ff2 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Wed, 8 Feb 2023 20:35:58 +0100 Subject: [PATCH 19/25] Update Task 015.c --- TASKS/Task 015.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..afd6f75 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,32 @@ 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() +{ + for (int i = 1; i <= 100; ++i) + { + if (i % 15 == 0) + { + printf("FizzBuzz"); + } + + else if (i % 5 == 0) + { + printf("Buzz"); + } + else if (i % 3 == 0) + { + printf("Fizz"); + } + else + { + printf("%d", i); + } + printf("\n"); + } +return (0); +} From 07f5300473a1a625d141f20c8b111c047cde7f8d Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sat, 11 Feb 2023 22:57:26 +0100 Subject: [PATCH 20/25] Update Task 016.c --- TASKS/Task 016.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 016.c b/TASKS/Task 016.c index 8700bc0..7503746 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 recFunc(int n) +{ + + if (n == 1) + { + return n; + } + else + { + return n * recFunc(n-1); + + } + +} + +int main() +{ + int num, sum; + printf("Enter a number\n"); + scanf("%d", &num); + sum = recFunc(num), + + printf("%d", sum); +} From 69cc74db5f6692e13bad814c32e8efaef023ce16 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sat, 11 Feb 2023 22:58:58 +0100 Subject: [PATCH 21/25] Update Task 017.c --- TASKS/Task 017.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 017.c b/TASKS/Task 017.c index f5ef778..3d466e9 100644 --- a/TASKS/Task 017.c +++ b/TASKS/Task 017.c @@ -8,4 +8,31 @@ Output: 21 // That is; 1+2+3+4+5+6 = 21 -*/ \ No newline at end of file +*/ + +#include + +int recFunc(int n) +{ + + if (n == 1) + { + return n; + } + else + { + return n + recFunc(n-1); + + } + +} + +int main() +{ + int num, sum; + printf("Enter a number\n"); + scanf("%d", &num); + sum = recFunc(num), + + printf("%d", sum); +} From c4f0c16f9350b164a382d9a584b76494e50c0802 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Mon, 13 Feb 2023 14:06:19 +0100 Subject: [PATCH 22/25] Update Task 018.c --- TASKS/Task 018.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 018.c b/TASKS/Task 018.c index 147ff9a..8ba3b9b 100644 --- a/TASKS/Task 018.c +++ b/TASKS/Task 018.c @@ -2,4 +2,31 @@ 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 power(int x, int y) +{ + int ans = 1; + while (y != 0) + { + ans *= x; + --y; + } + return (ans); +} + +int main() +{ + int n1, n2, result; + printf("Enter a base number: "); + scanf("%d", &n1); + printf("Enter an exponential: "); + scanf("%d", &n2); + + result = power(n1, n2); + printf("%d ^ %d = %d", n1, n2, result); + + return (0); +} From a2f4d09e1549abd65de637690f081edd6151de3e Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Tue, 14 Feb 2023 20:44:33 +0100 Subject: [PATCH 23/25] Update Task 019.c --- TASKS/Task 019.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/TASKS/Task 019.c b/TASKS/Task 019.c index 5cc5874..69b9cf6 100644 --- a/TASKS/Task 019.c +++ b/TASKS/Task 019.c @@ -1,4 +1,45 @@ /* Write a function to convert temperature from Celsius to Fahrenheit and vice versa. -*/ \ No newline at end of file +*/ + +/* + Write a function to convert temperature from Celsius to + Fahrenheit and vice versa. +*/ +#include + + +float fah_cel(float a) +{ + float sum = (a - 32) * 5/9; + return sum; +} + +float cel_fah(float c) +{ + float sum; + sum = (c * 9/5) + 32; + return sum; +} + + +int main() +{ + float num, result; + printf("Enter the Fahrenheit number: "); + scanf("%f", &num); + result = fah_cel(num); + + float cel, result2, result3; + printf("Enter Celsius: "); + scanf("%f", &cel); + + result2 = cel_fah(cel); + + + printf("%.1f'F = %.1f'C\n", num, result); + printf("%.1f'C = %.1f'F\n", cel, result2); + + return (0); +} From 550c74968fe8e0ed3ec9a55b617ef0e643f5fac8 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Wed, 15 Feb 2023 13:49:58 +0100 Subject: [PATCH 24/25] Update Task-22.c --- TASKS/Task-22.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/TASKS/Task-22.c b/TASKS/Task-22.c index 8cd01c4..1eae814 100644 --- a/TASKS/Task-22.c +++ b/TASKS/Task-22.c @@ -2,4 +2,15 @@ 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 age = 86; + int *ptr; + ptr = age; + printf("%d", age); + return (0); +} From 2d8364be1c77f0f7438b57d3ad7f7743d0e28266 Mon Sep 17 00:00:00 2001 From: JCTNIG <108359199+JCTNIG@users.noreply.github.com> Date: Sat, 18 Feb 2023 21:29:32 +0100 Subject: [PATCH 25/25] Update Task-23.c --- TASKS/Task-23.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/TASKS/Task-23.c b/TASKS/Task-23.c index dfddb16..2ae991e 100644 --- a/TASKS/Task-23.c +++ b/TASKS/Task-23.c @@ -1,4 +1,26 @@ /* Create a program that uses pointers to find the maximum value stored in an array. -*/ \ No newline at end of file +*/ + +#include + +int main() +{ + int nums[] = {95, 43, 6, 64, 23,89, 41, 15}; + int max; + int n = sizeof(nums) / sizeof(nums[0]); + + max = nums[3]; + + for (int i = 0; i < n; ++i) + { + if (nums[i] > max) + { + max = nums[i]; + } + + } + printf("the highest number is: %d\n", max); + return 0; +}