diff --git a/TASKS/1 b/TASKS/1 new file mode 100644 index 0000000..6c035e8 --- /dev/null +++ b/TASKS/1 @@ -0,0 +1,27 @@ +/* +Write a program in C to check a given number is even +or odd using the function. +*/ + +#include + +int main(void) +{ + int number, inputCheck; + + printf("Input a number: "); + scanf("%d", &number); + inputCheck = number%2; + + if (inputCheck == 0) + { + printf("The number %d is an even number\n", number); + } + else if (inputCheck == 1) + { + printf("The number %d is an odd number\n", number); + } + return 0; +} + + diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..ca5f641 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(void) +{ + char letter = 'a'; + for (letter = 'a'; letter <= 'z'; letter++) + { + if (letter != 'q' && letter != 'e') + { + printf("%c", letter); + } + } + printf("\n"); + return 0; +} diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..0155796 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,24 @@ 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 input your score: "); + scanf("%d", &score); + + if (score < 80) + { + printf("You are not eligible to be enrolled\n"); + } + else if (score >= 80) + { + printf("You can be enrolled\n"); + } + return 0; +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..a2dbfa8 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,30 @@ 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 number; + + printf("Input a number: "); + scanf("%d", &number); + + if (number == 0) + { + printf("This is zero\n"); + } + + else if (number%2 == 1) + { + printf("userInput is Odd\n"); + } + else if (number%2 == 0) + { + printf("userInput is even\n"); + } + return 0; +} + diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..8831bb3 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 name[20]; + int 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); + return 0; +} diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..a01769c 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,19 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ + +#include + +int main(void) +{ + int number, square; + + printf("Input a number: "); + scanf("%d", &number); + + square = number*number; + + printf("Square of %d is: %d\n", number, square); + return 0; +} diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..6c035e8 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,27 @@ /* 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 main(void) +{ + int number, inputCheck; + + printf("Input a number: "); + scanf("%d", &number); + inputCheck = number%2; + + if (inputCheck == 0) + { + printf("The number %d is an even number\n", number); + } + else if (inputCheck == 1) + { + printf("The number %d is an odd number\n", number); + } + return 0; +} + + diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..f2f555f 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,18 @@ 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 + +int main(void) +{ + char al; + + for (al = 'A'; al <= 'Z'; al++) + { + putchar(al); + } + putchar('\n'); + return 0; +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..baaca8a 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,18 @@ /*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 + +int main(void) +{ + char al; + + for (al = 'a'; al <= 'z'; al++) + { + putchar(al); + } + putchar('\n'); + return 0; +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..09c4df4 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,28 @@ 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 + +int main(void) +{ + char input; + + printf("Input a character: "); + scanf("%c", &input); + + if (input >= 'a' && input <= 'z') + { + printf("This is a lowercase letter\n"); + } + else if (input >= 'A' && input <= 'Z') + { + printf("This is an uppercase letter\n"); + } + else + { + printf("This character is not a letter!\n"); + } + return 0; +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..b8ea649 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,26 @@ 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 main(void) +{ + int n, result; + + printf("Input a number: "); + scanf("%d", &n); + + if (n >= 0) + { + result = n; + } + else if (n < 0) + { + result = -n; + } + + printf("The absolute value of %d is %d\n", n, result); + return 0; +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..2f9de9c 100644 --- a/TASKS/Task 011.c +++ b/TASKS/Task 011.c @@ -6,4 +6,18 @@ 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 main(void) +{ + int i, result; + + for (i = 0; i <= 12; i++) + { + result = 9 * i; + printf("9 x %d = %d\n", i, result); + } + return 0; +} diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..ec79aa7 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,20 @@ /*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 main(void) +{ + int i, j, sum; + + printf("Input the first integer: "); + scanf("%d", &i); + printf("Input the second integer: "); + scanf("%d", &j); + sum = i + j; + printf("%d + %d = %d\n", i, j, sum); + + return 0; +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..99d1336 100644 --- a/TASKS/Task 013.c +++ b/TASKS/Task 013.c @@ -3,4 +3,22 @@ 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 main() +{ + unsigned int n, i; + + printf("Input the starting integer: "); + scanf("%d", &n); + + for (i = n; i < 100; i++) + { + printf("%d ", i); + } + if (i == 100) + printf("%d\n", i); + return 0; +} diff --git a/TASKS/Task 014.c b/TASKS/Task 014.c index d139cd2..44b72ef 100644 --- a/TASKS/Task 014.c +++ b/TASKS/Task 014.c @@ -6,4 +6,19 @@ 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 + +int main(void) +{ + int i, j; + + for (i = 1; i <= 10; i++) + for (j = 0; j <= 14; j++) + if (j < 14) + printf("%d ", j); + else if (j == 14) + printf("%d\n", j); + return 0; +} diff --git a/TASKS/Task 015.c b/TASKS/Task 015.c index 7cac93a..57b7e1d 100644 --- a/TASKS/Task 015.c +++ b/TASKS/Task 015.c @@ -6,4 +6,24 @@ 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) +{ + unsigned int i; + + for (i = 1; i < 100; i++) + if ((i%3 == 0) && (i%5 != 0)) + printf("fizz "); + else if ((i%5 == 0) && (i%3 != 0)) + printf("buzz "); + else if ((i%3 == 0) && (i%5 == 0)) + printf("FizzBuzz "); + else + printf("%d ", i); + if (i == 100) + printf("buzz\n"); + return 0; +} diff --git a/TASKS/Task1 b/TASKS/Task1 new file mode 100755 index 0000000..7f42f7d Binary files /dev/null and b/TASKS/Task1 differ diff --git a/TASKS/Task10 b/TASKS/Task10 new file mode 100755 index 0000000..df70d9c Binary files /dev/null and b/TASKS/Task10 differ diff --git a/TASKS/Task11 b/TASKS/Task11 new file mode 100755 index 0000000..740fdd1 Binary files /dev/null and b/TASKS/Task11 differ diff --git a/TASKS/Task12 b/TASKS/Task12 new file mode 100755 index 0000000..200e683 Binary files /dev/null and b/TASKS/Task12 differ diff --git a/TASKS/Task13 b/TASKS/Task13 new file mode 100755 index 0000000..ff87e9d Binary files /dev/null and b/TASKS/Task13 differ diff --git a/TASKS/Task14 b/TASKS/Task14 new file mode 100755 index 0000000..db43f68 Binary files /dev/null and b/TASKS/Task14 differ diff --git a/TASKS/Task15 b/TASKS/Task15 new file mode 100755 index 0000000..2f0f344 Binary files /dev/null and b/TASKS/Task15 differ diff --git a/TASKS/Task2 b/TASKS/Task2 new file mode 100755 index 0000000..cde5655 Binary files /dev/null and b/TASKS/Task2 differ diff --git a/TASKS/Task3 b/TASKS/Task3 new file mode 100755 index 0000000..24ab4b5 Binary files /dev/null and b/TASKS/Task3 differ diff --git a/TASKS/Task4 b/TASKS/Task4 new file mode 100755 index 0000000..426ab04 Binary files /dev/null and b/TASKS/Task4 differ diff --git a/TASKS/Task5 b/TASKS/Task5 new file mode 100755 index 0000000..64cf046 Binary files /dev/null and b/TASKS/Task5 differ diff --git a/TASKS/Task6 b/TASKS/Task6 new file mode 100755 index 0000000..e50a5b2 Binary files /dev/null and b/TASKS/Task6 differ diff --git a/TASKS/Task7 b/TASKS/Task7 new file mode 100755 index 0000000..e7272f6 Binary files /dev/null and b/TASKS/Task7 differ diff --git a/TASKS/Task8 b/TASKS/Task8 new file mode 100755 index 0000000..5189327 Binary files /dev/null and b/TASKS/Task8 differ diff --git a/TASKS/Task9 b/TASKS/Task9 new file mode 100755 index 0000000..1b98be7 Binary files /dev/null and b/TASKS/Task9 differ