Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4b38fc2
Solution to all tasks 1 - 15 - Dukeson
Sampul-CodeMine Jan 21, 2023
bd30395
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Jan 27, 2023
ff360d3
Answer to Task 16
Sampul-CodeMine Jan 27, 2023
e95f2fe
Update Task 017.c
Sampul-CodeMine Jan 27, 2023
45ac648
Solution to task 18
Sampul-CodeMine Jan 27, 2023
1352ca5
Solution to Task 1 - 18 - Dukeson
Sampul-CodeMine Jan 27, 2023
ce06e17
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Jan 27, 2023
7df457c
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Jan 31, 2023
327121c
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Feb 1, 2023
17fb40e
Solution to task 19 - Dukeson
Sampul-CodeMine Feb 1, 2023
e49f4da
Solution to task 19 - Dukeson
Sampul-CodeMine Feb 1, 2023
0bf6c54
Solution to some of the task
Sampul-CodeMine Feb 1, 2023
05467a9
,Solution task - Dukeson
Sampul-CodeMine Feb 2, 2023
2dbd324
Some of the solution to the task - Dukeson
Sampul-CodeMine Feb 4, 2023
c4a79ef
Some solution to the task given - Dukeson
Sampul-CodeMine Feb 4, 2023
5bdda53
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Feb 4, 2023
b0e715d
,Solution to task - Dukeson
Sampul-CodeMine Feb 4, 2023
0b7324f
,Solution to task - Dukeson
Sampul-CodeMine Feb 5, 2023
0f21b1f
Updated - Dukeson
Sampul-CodeMine Feb 5, 2023
eaacff3
Updated - Dukeson
Sampul-CodeMine Feb 5, 2023
5b93a4f
Updated - Dukeson
Sampul-CodeMine Feb 5, 2023
34b4b81
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Feb 8, 2023
38acb30
Some solutions to some of the tasks that was given - Dukeson
Sampul-CodeMine Feb 8, 2023
e0cee4f
Some solutions to some of the tasks that was given - Dukeson
Sampul-CodeMine Feb 8, 2023
22194d0
Solution to tasks.
Sampul-CodeMine Feb 15, 2023
55fb77e
Merge branch 'davidinmichael:main' into main
Sampul-CodeMine Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TASKS/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
this directory contains tasks on each of the lessons of c programming, attempt each of them before asking or checking the solutions.

25 changes: 20 additions & 5 deletions TASKS/Task 001.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/* Write your program after the comment
Write a program that prints the alphabet in lowercase, followed by a new line.
#include <stdio.h>
#include <stdlib.h>

Print all the letters except q and e
/**
* Write your program after the comment
* Write a program that prints the alphabet in lowercase, followed by a new line.
* Print all the letters except q and e
* use printf
*/

use printf
*/
int main(void)
{
char alpha;

for (alpha = 'a'; alpha <= 'z'; alpha++)
{
if (alpha == 'e' || alpha == 'q')
continue;
printf("%c", alpha);
}
printf("\n");
}
32 changes: 26 additions & 6 deletions TASKS/Task 002.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/* Write your program after the comment
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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

/**
* Write your program after the comment
* 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 eligible to be enrolled.
* If the score is greater than or equal 80, they can be enrolled.
*/

int main(void)
{
int score = 0;
printf("Enter a Score:\t");
if (scanf("%d", &score) == 1)
{
if (score < 80)
printf("You are not eligible to be enrolled.");
else if (score >= 80)
printf("You can be enrolled.");
}
else
printf("Your input is not a numeric data.");
return 0;
}
28 changes: 21 additions & 7 deletions TASKS/Task 003.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/* Write your program after the comment
Write a program that reads input from user (Number)
If the number is Odd, display 'userInput is Odd'
If the number is even, display 'userInput is even'
If the number is zero, display 'This is zero'
#include <stdio.h>
#include <stdlib.h>

NOTE: 'userInput' should be the number entered by the user.
/**
* Write your program after the comment
* Write a program that reads input from user (Number)
* If the number is Odd, display 'userInput is Odd'
* If the number is even, display 'userInput is even'
* If the number is zero, display 'This is zero'
*
* NOTE: 'userInput' should be the number entered by the user.
*/

*/
int main(void)
{
int num = 0;

printf("Enter Number:\t");
scanf("%d", &num);

(num == 0) ? printf("Input is Zero") : ((num % 2 == 0) ? printf("Input is even") : printf("input is odd"));
return (0);
}
42 changes: 31 additions & 11 deletions TASKS/Task 004.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
/* Write your program after the comment
Write a program that asks and reads the following input from a use;
Your name
Your age
and then displays; Your name is 'name' and you are 'age' years old.
#include <stdio.h>
#include <stdlib.h>

Example;
what is your name: David
How old are you?: 65
/**
* Write your program after the comment
* Write a program that asks and reads the following input from a use;
* Your name
* Your age
* and then displays; Your name is 'name' and you are 'age' years old.
*
* Example;
*
* what is your name: David
* How old are you?: 65
*
* Output:
* Your name is David and you are 65 years old.
*/

Output:
Your name is David and you are 65 years old.
int main(void)
{
int age = 0;
char name[100];

*/
printf("Enter Name:\t");
scanf("%s", name);

printf("Enter Age:\t");
scanf("%d", &age);

printf("Your name is %s and you are %d years old.", name, age);

return (0);
}
31 changes: 27 additions & 4 deletions TASKS/Task 005.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
/*
Write a program in C to find the square of any number
using the function.
*/
#include <stdio.h>

/**
* Write a program in C to find the square of any number
* using the function.
*/

void return_square()
{
int num = 0, result;

printf("Enter a Number:\t");
if (scanf("%d", &num) == 1)
result = (num * num);
else
result = 0;
if (result == 0)
printf("\nThe data entered is not a number. The result is %d", result);
else
printf("\nThe square of %d = %d", num, result);
}

int main(void)
{
return_square();
return (0);
}
24 changes: 23 additions & 1 deletion TASKS/Task 006.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
#include <stdio.h>
/*
Write a program in C to check a given number is even
or odd using the function.
*/
*/
void type_checker()
{
int num = 0;

printf("Enter a Number:\t");
if (scanf("%d", &num) == 1)
{
if ((num % 2) == 0)
printf("\nThe number %d is an even number.", num);
else
printf("\nThe number %d is an odd number.", num);
}
else
printf("\nThe data entered is not a number.");

}
int main(void)
{
type_checker();
return (0);
}
35 changes: 34 additions & 1 deletion TASKS/Task 007.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
#include <stdio.h>
#include <ctype.h>

/*
write your solution after the comment
Write a function that prints the alphabet, in uppercase,
followed by a new line.
*/
*/

void to_upper_case_one()
{
char n;

for (n = 'A'; n <= 'Z'; n++)
{
printf("%c", n);
}
printf("\n");
}

void to_upper_case_two()
{
char n;

for (n = 'a'; n <= 'z'; n++)
{
printf("%c", toupper(n));
}
printf("\n");
}

int main(void)
{
to_upper_case_one();
to_upper_case_two();

return (0);
}
35 changes: 34 additions & 1 deletion TASKS/Task 008.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
#include <stdio.h>
#include <ctype.h>

/*write your solution after the comment
Write a function that prints the alphabet, in lowercase
followed by a new line.
*/
*/

void to_lower_case_one()
{
char n;

for (n = 'a'; n <= 'z'; n++)
{
printf("%c", n);
}
printf("\n");
}

void to_lower_case_two()
{
char n;

for (n = 'A'; n <= 'Z'; n++)
{
printf("%c", tolower(n));
}
printf("\n");
}

int main(void)
{
to_lower_case_one();
to_lower_case_two();

return (0);
}
25 changes: 24 additions & 1 deletion TASKS/Task 009.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>

/*write your solution after the comment
Write a function that checks for lowercase character.
That is, when passed in an arguments, it checks if the
argument is lowercase or uppercase.
*/
*/
void check_case(char chr)
{
if ( chr >= 'a' && chr <= 'z')
printf("\n%c is a lower cased character.", chr);
else if (chr >= 'A' && chr <= 'Z')
printf("\n%c is an upper cased character.", chr);
else
printf("\nKindly provide a character.");
}
int main(void)
{
char str;

printf("Enter a character:\t");
scanf("%c", &str);
check_case(str);

return (0);
}
27 changes: 26 additions & 1 deletion TASKS/Task 010.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#include <stdio.h>

/*write your solution after the comment
Write a function that computes the absolute
value of an integer.
Understand what an absolute value is, before attempting it.
*/
*/
int get_absolute(int num)
{
if (num < 0)
num *= -1;
return (num);
}

int main(void)
{
int num = 0;
int result = 0;

printf("Enter a Number:\t");
if (scanf("%d", &num) == 1)
{
result = get_absolute(num);
printf("The absolute value of %d = %d", num, result);
}
else
printf("\nThe data entered is not a number.");

return (0);
}
18 changes: 17 additions & 1 deletion TASKS/Task 011.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>

/*write your solution after the comment
Write a function that prints the 9 times table,
starting with 0.
Expand All @@ -6,4 +8,18 @@ Output should look like this;
9 x 1 = 9
9 x 2 = 18
... and so on till 12
*/
*/

void times_table()
{
int i = 9, j;

for (j = 0; j <= 12; j++)
printf("%d * %d = %d\n", i, j, (i * j));
printf("\n");
}
int main(void)
{
times_table();
return (0);
}
Loading