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
2 changes: 2 additions & 0 deletions TASKS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.exe
*.o
16 changes: 15 additions & 1 deletion TASKS/Task 001.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,18 @@ 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 alpha;

for (alpha = 'a'; alpha <= 'z'; alpha++)
{
if (alpha != 'e' && alpha != 'q')
printf("%c ", alpha);
}
printf("\n");
return(0);
}
25 changes: 24 additions & 1 deletion TASKS/Task 002.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,27 @@ 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()
{
int check;

printf("What is your score ?");
scanf("%i", &check);// take user score
user_score(check);
return (0);
}

void user_score(int score)
{
// check if score is less than 80
if (score < 80)
{
printf("You are not eligible");
}
else// above 80
{
printf("You are eligible");
}
}
33 changes: 32 additions & 1 deletion TASKS/Task 003.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,35 @@ If the number is zero, display 'This is zero'

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

*/
*/
#include<stdio.h>
void read_int(int num)
{
// check if num is even
if (num % 2 == 0)
{
printf("%i is an even number\n", num);
}
else if (num % 2 == 1)
{
printf("%i is an odd number\n", num);
}
else if (num == 0)
{
printf("The number is Zero (%i)\n", num);
}
else
{
printf("unknown input!\n");
}
}

int main(void)
{
int check;

printf("Choose your lucky number!: ");
scanf("%i", &check);
read_int(check);
return (0);
}
21 changes: 20 additions & 1 deletion TASKS/Task 004.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,23 @@ How old are you?: 65
Output:
Your name is David and you are 65 years old.

*/
*/
// char user_profile(char name, int age)
// {
// printf("Your name is %s and you are %i years old!\n", name, age);
// }

int main(void)
{
int age;
char name[100];

printf("What is your name?");
scanf("%s", name);
printf("How old are you?");
scanf("%i", &age);
// user_profile(name,age);
printf("Your name is %s and you are %i years old!\n", name, age);
return (0);

}
16 changes: 15 additions & 1 deletion TASKS/Task 005.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
/*
Write a program in C to find the square of any number
using the function.
*/
*/
int sq_num(x)
{
return (x * x);
}

int main(void)
{
int x;

printf("input a number: ");
scanf("%i", &x);
printf("The square of %i is %i", x, sq_num(x));
return (0);
}
23 changes: 22 additions & 1 deletion TASKS/Task 006.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
/*
Write a program in C to check a given number is even
or odd using the function.
*/
*/
int main(void)
{
int num;

printf("Input a number \n");
scanf("%i", &num);
even_odd(num);
return (0);
}

void even_odd(int check)
{
if (check % 2 == 0)
{
printf("This an even number");
}
else
{
printf("This is an odd number");
}
}
22 changes: 21 additions & 1 deletion TASKS/Task 007.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@
write your solution after the comment
Write a function that prints the alphabet, in uppercase,
followed by a new line.
*/
*/

void print_abc(char abc)
{
abc = 'A';

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

int main(void)
{
char abc = 'A';

print_abc(abc);
return (0);
}
21 changes: 20 additions & 1 deletion TASKS/Task 008.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
/*write your solution after the comment
Write a function that prints the alphabet, in lowercase
followed by a new line.
*/
*/
void print_abc(char abc)
{
abc = 'a';

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

int main(void)
{
char abc = 'a';

print_abc(abc);
return (0);
}
20 changes: 19 additions & 1 deletion TASKS/Task 009.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,22 @@
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 _islower(char low)
{
if (low >= 'a' && low <= 'z' )
printf("%c - This is in lowercase", low);
else
printf("This is in uppercase");
}

int main(void)
{
char let;

printf("input an argument\n");
scanf("%c", &let);
_islower(let);
return(0);
}
18 changes: 17 additions & 1 deletion TASKS/Task 010.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,20 @@
Write a function that computes the absolute
value of an integer.
Understand what an absolute value is, before attempting it.
*/
*/
#include<stdio.h>
int abs(int x)
{
int y;

y = y * -1;
return(y);
}

int main(void)
{
int z = -3;

abs(z);
return(0);
}
23 changes: 22 additions & 1 deletion TASKS/Task 011.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,25 @@ Output should look like this;
9 x 1 = 9
9 x 2 = 18
... and so on till 12
*/
*/
#include<stdio.h>
void times_table(int times)
{
int i, j;

for (i = times; i <= times; i++) // outer loop
{
for (j = 1; j < 12; j++) //inner loop
{
printf("%02d * %02d = %03d\n", i, j,(i * j));
}
printf("\n");
}
}
int main(void)
{
int num;
printf("print time table of ");
scanf("%d", &num);
times_table(num);
}
13 changes: 12 additions & 1 deletion TASKS/Task 012.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
/*Write your solution after the comment
Write a function that adds two integers and prints
the result.
*/
*/
#include<stdio.h>
int add_int(int x, int y)
{
return(x + y);
}

int main(void)
{
add_int(4, 5);
printf("the addition of %d and %d is %d", 4, 5, add_int(4,5));
}
20 changes: 19 additions & 1 deletion TASKS/Task 013.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
*/
#include<stdio.h>
void natuaral_num(int nat)
{
int i;
for (i = nat; i <= 100; i++) // start from the input
{
printf("%i ", i);
}
printf("\n");
}
int main(void)
{
int n;

printf("Printing of natural numbers. Choose a number!\n");
scanf("%i", &n);
natuaral_num(n);
}
18 changes: 17 additions & 1 deletion TASKS/Task 014.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,20 @@ 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
*/
*/
#include<stdio.h>
int main(void)
{
int i, j;

for (i = 0; i < 10; i++) // runs 10 times outer loop
{
for (j = 0; j < 15; j++) // inner loop
{
printf("%d ", j); // prints from 0 - 14
}
printf("\n"); // prints new line after each iteration
}
printf("\n"); // prints new line after the loop is done
return(0);
}
Loading