Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion TASKS/Task 001.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
*/

#include <stdio.h>

int main(void)
{
char alp;

for (alp = 'a'; alp <= 'z'; alp++)
{
if (alp == 'e' || alp == 'q')
{
continue;
}
printf("%c", alp);
}
printf("\n");
return (0);
}
20 changes: 19 additions & 1 deletion TASKS/Task 002.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
*/

#include <stdio.h>

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);
}
23 changes: 22 additions & 1 deletion TASKS/Task 003.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,25 @@ If the number is zero, display 'This is zero'

NOTE: 'userInput' should be the number entered by the user.

*/
*/

#include <stdio.h>

int main(void)
{
int userInput;

printf("Please enter your magic number ");
scanf("%d", &userInput);

if ((userInput % 2) == 1)
printf("Your magic number is odd!\n");
/*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);
}
20 changes: 18 additions & 2 deletions TASKS/Task 004.c
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,4 +11,20 @@ How old are you?: 65
Output:
Your name is David and you are 65 years old.

*/
*/

#include <stdio.h>
int main(void)
{
char name[50];
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!", name, age);
putchar('\n');
return (0);
}
26 changes: 25 additions & 1 deletion TASKS/Task 005.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
/*
Write a program in C to find the square of any number
using the function.
*/
*/

#include <stdio.h>

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);
}
24 changes: 23 additions & 1 deletion TASKS/Task 006.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
/*
Write a program in C to check a given number is even
or odd using the function.
*/
*/

#include <stdio.h>

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");
}
24 changes: 23 additions & 1 deletion TASKS/Task 007.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@
write your solution after the comment
Write a function that prints the alphabet, in uppercase,
followed by a new line.
*/
*/

#include <stdio.h>

void alp();
int main(void)
{
alp();
return (0);
}

void alp()
{
int p;
p = 65;

while (p <= 90)
{
putchar(p);
p++;
}
putchar('\n');
}
29 changes: 26 additions & 3 deletions TASKS/Task 008.c
Original file line number Diff line number Diff line change
@@ -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.
*/
*/

#include <stdio.h>

void alp();
int main(void)
{
alp();
return (0);
}

void alp()
{
int p;
p = 'a';

while (p <= 'z')
{
putchar(p);
p++;
}
putchar('\n');
}
30 changes: 29 additions & 1 deletion TASKS/Task 009.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
*/

#include <stdio.h>

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);
}
}
43 changes: 42 additions & 1 deletion TASKS/Task 010.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,45 @@
Write a function that computes the absolute
value of an integer.
Understand what an absolute value is, before attempting it.
*/
*/

#include <stdio.h>

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);
}
25 changes: 24 additions & 1 deletion TASKS/Task 011.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,27 @@ Output should look like this;
9 x 1 = 9
9 x 2 = 18
... and so on till 12
*/
*/

#include <stdio.h>

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 ();*/
}
29 changes: 28 additions & 1 deletion TASKS/Task 012.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
/*Write your solution after the comment
Write a function that adds two integers and prints
the result.
*/
*/

#include <stdio.h>

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);
}
Loading