diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..0041333 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 LowerAlpha; + + for (LowerAlpha = 'a'; LowerAlpha >= 'z'; LowerAlpha++) + { + if (LowerAlpha != 'e' || LowerAlpha != 'q') + printf("%c", LowerAlpha) + } + printf("\n") + return; +} \ No newline at end of file diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..70e1203 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,23 @@ 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) +{ + double score; + + printf("Enter you score:"); + scanf("%lf", &score); + + if (score >= 80) + { + printf("You are eligible to be enrolled\n"); + } + else if (score < 80) + { + printf("You are not eligible to be enrolled\n"); + } +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..c247201 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,28 @@ 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 num; + + printf("Enter and integer: "); + scanf("%d", &num); + + if (num % 2 == 1); + { + printf('userInput is Odd'); + } + else if (num % 2 == 0); + { + printf('userInput is even'); + } + else + { + printf('This is zero'); + } + return; +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..3e387f1 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(void) +{ + char StrName[20]; + int age; + + printf("Enter your name: "); + scanf("%s", &StrName); + + printf("Enter your age: "); + scanf("%d", &age); + + printf("Your name is %s and you are %d years old\n", StrName, age); + return; + } diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..e85e333 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,22 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ +#include + +int sqr(int num) +{ + return num * num; +} +int main() +{ + int num, result; + + printf("Enter a number: "); + scanf("%d", &num); + + result = sqr(num); + printf("Square of %d is %d", num, result); + + return 0; +} diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..df6462b 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,28 @@ /* 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 odd_even(int num) +{ + if (num % 2 == 0) + { + printf("It's even\n"); + } + else if (num % 2 != 0) + { + printf("It's odd\n"); + } + return; +} + +int main() +{ + int num; + printf("Enter an integer: "); + scanf("%d", &num); + + odd_even(num); +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..d7dfbf3 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 + +void UpperAlph() +{ + char Caps; + + for (Caps = 'A'; Caps <= 'Z'; Caps++) + { + printf("%c ", Caps); + } +} + +int main() +{ + UpperAlph(); +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..21add52 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 LowerAlph() +{ + char letters; + + for (letters = 'a'; letters <= 'z'; letters++) + { + printf("%c ", letters); + } +} + +int main() +{ + LowerAlph(); +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..d1ac866 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,27 @@ 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 +*/ + +void Lower(char letter) +{ + + if (letter >= 'a' && letter <= 'z') + { + printf("It's lowercase "); + } + else if (letter >= 'A' && letter <= 'Z') + { + printf("It's not lowercase "); + } +} + +int main() +{ + char letter; + + printf("Enter a letter: "); + scanf("%c", &letter); + + Lower(letter); +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..b2ea00a 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,29 @@ 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 AbsVal(int num) +{ + if(num < 0) + { + return (-num); + } + if (num >= 0) + { + return (num); + } +} + +int main() +{ + int num; + printf("Enter a number: "); + scanf("%d", &num); + + int Absolute = AbsVal(num); + + printf("The absolute value if %d is %d\n", num, Absolute); +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..eb07d5c 100644 --- a/TASKS/Task 011.c +++ b/TASKS/Task 011.c @@ -6,4 +6,21 @@ 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 NTab() +{ + int i; + + for (i = 0; i <= 12; i++) + { + printf("%d x %d = %d\n", 9, i, 9 * i); + } +} + +int main() +{ + NTab(); +} diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..4eea3d2 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 + +void AddInt(int num, int num1) +{ + int sum = num + num1; + + printf("The sum of %d and %d = %d\n", num, num1, sum); +} + +int main() +{ + int num1, num2; + + printf("Enter an integer: "); + scanf("%d", &num1); + printf("Enter another integer: "); + scanf("%d", &num2); + AddInt(num1, num2); +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..c3e14ff 100644 --- a/TASKS/Task 013.c +++ b/TASKS/Task 013.c @@ -3,4 +3,36 @@ 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 NatNum(int n) +{ + int i; + if (n >= 0 && n <= 100) + { + for (i = n; i <= 100; i++) + { + printf("%d ", i); + } + } + else if (n < 0) + { + printf("This is not a natural number\n"); + } + else + { + printf("This number exceeds 100\n"); + } +} + + +int main() +{ + int num; + + printf("Enter a number from 0 - 100: "); + scanf("%d", &num); + NatNum(num); +} diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..71df5bc 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 PrintNum() +{ + int i = 1, j = 0; + + while (i <= 10) + { + while (j <= 14) + { + printf("%d ", j); + j++; + } + printf("\n"); + i++; + j = 0; + } +} + +int main() +{ + PrintNum(); +} diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..f23583e 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,35 @@ 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() +{ + int n; + for (n = 1; n <= 100; n++) + { + if (n % 3 == 0 && n % 5 != 0) + { + printf("Fizz "); + } + else if (n % 5 == 0 && n % 3 !=0) + { + printf("Buzz "); + } + else if (n % 3 == 0 && n % 5 == 0) + { + printf("FizzBuzz "); + } + else + { + printf("%d ", n); + } + } + printf("\n"); +} + +int main() +{ + FizzBuzz(); +} diff --git a/TASKS/Task 016.c b/TASKS/Task 016.c index 8700bc0..2f24d2a 100644 --- a/TASKS/Task 016.c +++ b/TASKS/Task 016.c @@ -8,4 +8,28 @@ Output: 720 // That is 1x2x3x4x5x6 = 720 -*/ \ No newline at end of file +*/ +#include + +int prodAll(int n) +{ + if (n == 1) + { + return 1; + } + else + return n * prodAll(n - 1); +} + +int main() +{ + int num; + + printf("Enter a number: "); + + scanf("%d", &num); + + printf("The product of integers from 1 to %d is %d", num, prodAll(num)); + + return 0; +} diff --git a/TASKS/Task 017.c b/TASKS/Task 017.c index f5ef778..58d89ed 100644 --- a/TASKS/Task 017.c +++ b/TASKS/Task 017.c @@ -8,4 +8,20 @@ Output: 21 // That is; 1+2+3+4+5+6 = 21 -*/ \ No newline at end of file +*/ +#include + +int sumAll(int n) { + if (n == 1) { + return 1; + } + return n + sumAll(n - 1); +} + +int main() { + int num; + printf("Enter a number: "); + scanf("%d", &num); + printf("The sum of integers from 1 to %d is %d", num, sumAll(num)); + return 0; +} diff --git a/TASKS/Task 018.c b/TASKS/Task 018.c index 147ff9a..95a0beb 100644 --- a/TASKS/Task 018.c +++ b/TASKS/Task 018.c @@ -2,4 +2,18 @@ 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 +#include + +int power(int x, int y) +{ + return pow(x, y); +} +int main() +{ + int num1 = 3; + int num2 = 5; + + printf("%d raised to the power of %d is %d", num1, num2, power(num1, num2)); +} diff --git a/TASKS/Task 019.c b/TASKS/Task 019.c index 5cc5874..fb51836 100644 --- a/TASKS/Task 019.c +++ b/TASKS/Task 019.c @@ -1,4 +1,28 @@ /* Write a function to convert temperature from Celsius to Fahrenheit and vice versa. -*/ \ No newline at end of file +*/ +#include + +float convert_Temperature(float temp, char unit) { + if (unit == 'C') { + return (temp * 9/5) + 32; + } else if (unit == 'F') { + return (temp - 32) * 5/9; + } else { + printf("Invalid unit. Use 'C' for Celsius or 'F' for Fahrenheit.\n"); + return 0; + } +} +int main() +{ + char unit; + float temp; + printf("Enter your temperature: "); + scanf("%f", &temp); + printf("Indicate F or C: "); + scanf(" %c", &unit); + + float Answer = convert_Temperature(temp, unit); + printf("Answer: %f", Answer); +} diff --git a/TASKS/a.exe b/TASKS/a.exe new file mode 100644 index 0000000..ff59284 Binary files /dev/null and b/TASKS/a.exe differ