diff --git a/TASKS/Task 001.c b/TASKS/Task 001.c index 24be041..c394f75 100644 --- a/TASKS/Task 001.c +++ b/TASKS/Task 001.c @@ -1,7 +1,15 @@ -/* Write your program after the comment + /* 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 -*/ \ No newline at end of file +*/ +#include + +int main() { + char i; + for (i = 'a'; i <='z'; ++i) + if (i != 'e' && i != 'q') + printf("%c", i); + + return 0; +} diff --git a/TASKS/Task 002.c b/TASKS/Task 002.c index 5cdd390..7c2e3f1 100644 --- a/TASKS/Task 002.c +++ b/TASKS/Task 002.c @@ -3,4 +3,17 @@ 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() { + int score; + printf("Enter an integer: "); + scanf("%d", &score); + if (score < 80) { + printf("You are not eligible to enrolled"); + } else { + printf("You are enrolled"); + } + return 0; +} diff --git a/TASKS/Task 003.c b/TASKS/Task 003.c index 7fca79c..17c76c6 100644 --- a/TASKS/Task 003.c +++ b/TASKS/Task 003.c @@ -6,4 +6,20 @@ 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() { + int n; + printf("Enter an integer: "); + scanf("%d", &n); + if (n == 0) { + printf("You entered zero\n"); + } + else if (n %2==0) { + printf("You entered an even number\n"); + } else { + printf("You entered an odd number\n"); + } + return 0; +} diff --git a/TASKS/Task 004.c b/TASKS/Task 004.c index 17ee38c..666e97a 100644 --- a/TASKS/Task 004.c +++ b/TASKS/Task 004.c @@ -11,4 +11,18 @@ 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() { + char n[50]; + int a; +//where n represents the name of user, while a represents the user's age + printf("Enter Your name: \n"); + scanf("%s", n); + printf("Enter your Age: \n"); + scanf("%d", &a); + printf("Your name is %s and you are %d years old.\n", n, a); + + return 0; +} diff --git a/TASKS/Task 005.c b/TASKS/Task 005.c index db32ab3..933e3cd 100644 --- a/TASKS/Task 005.c +++ b/TASKS/Task 005.c @@ -1,4 +1,14 @@ /* Write a program in C to find the square of any number using the function. -*/ \ No newline at end of file +*/ +#include + +int main() { + int num = 6; + + int square = num * num; + printf("The square of your number is: %d", square); + + return 0; +} diff --git a/TASKS/Task 006.c b/TASKS/Task 006.c index dc0b9af..91535a8 100644 --- a/TASKS/Task 006.c +++ b/TASKS/Task 006.c @@ -1,4 +1,23 @@ /* Write a program in C to check a given number is even or odd using the function. -*/ \ No newline at end of file +*/ +// Online C compiler to run C program online +#include +void even_or_odd() +{ + int num; + printf("Enter a number: "); + if (scanf("%d", &num)) + { + if (num%2 == 0) + printf("%d is an even number\n",num); + else + printf("%d is an odd number\n", num); + } +} +int main (void) +{ + even_or_odd(); + return (0); +} diff --git a/TASKS/Task 007.c b/TASKS/Task 007.c index 07ea0fb..d5054bf 100644 --- a/TASKS/Task 007.c +++ b/TASKS/Task 007.c @@ -2,4 +2,15 @@ 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 capital_letters() +{ + for (char i = 'A'; i <= 'Z'; ++i) + printf("%c\n", i); +} +int main() +{ + capital_letters(); + return (0); +} diff --git a/TASKS/Task 008.c b/TASKS/Task 008.c index 0a815b2..a640a32 100644 --- a/TASKS/Task 008.c +++ b/TASKS/Task 008.c @@ -1,4 +1,15 @@ /*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 capital_letters() +{ + for (char i = 'a'; i <= 'z'; ++i) + printf("%c\n", i); +} +int main() +{ + capital_letters(); + return (0); +} diff --git a/TASKS/Task 009.c b/TASKS/Task 009.c index d481f90..0dfd032 100644 --- a/TASKS/Task 009.c +++ b/TASKS/Task 009.c @@ -2,4 +2,21 @@ 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 +*/ +// Online C compiler to run C program online +#include +void zero_to_14_10x() +{ + int x,y; + for(x >= 0; x <= 14; ++x) + { + for(y=0; y<15; y++) + printf("%d\n", x); + } +} +int main() +{ + zero_to_14_10x(); + + return 0; +} diff --git a/TASKS/Task 010.c b/TASKS/Task 010.c index 62c07e9..49eedfa 100644 --- a/TASKS/Task 010.c +++ b/TASKS/Task 010.c @@ -2,4 +2,15 @@ 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 abs(int x) { + return x < 0 ? -x : x; +} + +int main() { + int x = -5; + printf("The absolute value of %d is %d.\n", x, abs(x)); + return 0; +} diff --git a/TASKS/Task 011.c b/TASKS/Task 011.c index 96c4add..41a6c52 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 +void table_9() +{ + int x; + int y; + if (x = 9) + for (y>=0; y<=12; y++) + printf("%d X %d = %d\n", x, y,x*y); +} +int main() +{ + table_9(); + return 0; +} diff --git a/TASKS/Task 012.c b/TASKS/Task 012.c index 735a015..215414d 100644 --- a/TASKS/Task 012.c +++ b/TASKS/Task 012.c @@ -1,4 +1,36 @@ /*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 sum() +{ + int x; + int y; + printf("Enter an integer: "); + scanf("%d", &x); + printf("Enter another integer you want to add: "); + scanf("%d", &y); + printf("%d + %d = %d\n", x, y,x+y); +} +int main() +{ + sum(); + return 0; +} + +OR + +#include +void sum() +{ + int x; + int y; + if (x = 9, y=8) + printf("%d + %d = %d\n", x, y,x+y); +} +int main() +{ + sum(); + return 0; +} diff --git a/TASKS/Task 013.c b/TASKS/Task 013.c index 068a6cc..0e1841e 100644 --- a/TASKS/Task 013.c +++ b/TASKS/Task 013.c @@ -3,4 +3,18 @@ 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 nat() +{ + int n; + printf("Enter an integer: "); + scanf("%d", &n); + for (n >=n; n<=100; n++) + printf("%d\n", n); +} +int main() +{ + nat(); + return 0; +}