This project delves deeper into the world of C programming, covering essential topics such as variables, conditional statements, and loops. The objective is for the learner to have a solid foundation to build more complex programs and logic.
By the end of this project, I have developed the ability to explain the following concepts without external assistance:
- Applying arithmetic operators effectively in C.
- Utilizing logical and relational operators to make informed decisions.
- Grasping and utilizing the concepts of if and if...else statements for effective branching.
- Declaring and assigning values to variables of different data types.
- Displaying variable values using the
printf
function. - Implementing the while loop for iterative processes and efficient control flow.
- Working with ASCII characters and understanding their role.
- Recognizing the significance of compiler flags like
-m32
and-m64
.
This directory contains a collection of files, each serving a unique purpose:
0.Positive anything is better than negative nothing: C program that prints whether a randomly generated number is positive or negative, followed by a new line.
- Completion of this source code.
- Stores a different random number every time the program is run.
- Prints the number followed by
is positive
if the number is greater than 0,is zero
if the number is zero, oris negative
if the number is less than 0.
Test Cases:
$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 0-positive_or_negative.c -o 0-positive_or_negative
$ ./0-positive_or_negative
-520693284 is negative
$ ./0-positive_or_negative
-973398895 is negative
$ ./0-positive_or_negative
-199220452 is negative
$ ./0-positive_or_negative
561319348 is positive
$ ./0-positive_or_negative
561319348 is positive
$ ./0-positive_or_negative
266853958 is positive
$ ./0-positive_or_negative
-48147767 is negative
$ ./0-positive_or_negative
0 is zero
1.The last digit: C program that prints the last digit of a randomly generated number, followed by a new line
- Completion of this source code.
- Stores a different value every time the program is run.
- Prints the string
Last digit of
[number]is
[last_digit]and is
followed bygreater than 5
if the digit is greater than 5,0
if the digit is 0, orless than 6 and not 0
if the digit is less than 6 and not 0.
Test Cases
$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 1-last_digit.c -o 1-last_digit
$ ./1-last_digit
Last digit of 629438752 is 2 and is less than 6 and not 0
$ ./1-last_digit
Last digit of -748255693 is -3 and is less than 6 and not 0
2. I sometimes suffer from insomnia. And when I can't fall asleep, I play what I call the alphabet game:
C program that prints the alphabet in lowercase, followed by a new line, using only the putchar
function exactly twice.
Test Cases
$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 2-print_alphabet.c -o 2-print_alphabet
$ ./2-print_alphabet
abcdefghijklmnopqrstuvwxyz
3. When I was having that alphabet soup, I never thought that it would pay off:
C program that prints the alphabet in lowercase, then in uppercase, followed by a new line, using only the putchar
function exactly three times.
Test Cases
$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 3-print_alphabets.c -o 3-print_alphabets
$ ./3-print_alphabets | cat -e
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$
4. alphABET:
C program that prints the alphabet in lowercase except for the letters q
and e
, followed by a new line, using only the putchar
function exactly twice.
Test Cases
$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 4-print_alphabt.c -o 4-print_alphabt
$ ./4-print_alphabt
abcdfghijklmnoprstuvwxyz
$ ./4-print_alphabt | grep [eq]
-
Numbers:
5-print_numbers.c - C program that prints all single-digit numbers of base 10 starting from 0, followed by a new line.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 5-print_numbers.c -o 5-print_numbers $ ./5-print_numbers 0123456789
-
Numberz:
6-print_numberz.c - C program that prints all single-digit numbers of base 10 starting from 0, followed by a new line, using only the
putchar
function exactly twice without any variables of type char.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 6-print_numberz.c -o 6-print_numberz $ ./6-print_numberz 0123456789
-
7-print_tebahpla.c - C program that prints the lowercase alphabet in reverse, followed by a new line, using only the
putchar
function exactly twice.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 7-print_tebahpla.c -o 7-print_tebahpla $ ./7-print_tebahpla zyxwvutsrqponmlkjihgfedcba
-
Hexadecimal:
8-print_base16.c - C program that prints all the numbers of base 16 in lowercase, followed by a new line, using only the
putchar
function exactly three times.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 8-print_base16.c -o 8-print_base16 $ ./8-print_base16 0123456789abcdef
-
Patience, persistence and perspiration make an unbeatable combination for success:
9-print_comb.c - C program that prints all possible combinations of single-digit numbers, using only the
putchar
function exactly four times without any variables of type char:
Numbers are separated by,
, followed by a space.
Numbers are printed in ascending order.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 9-print_comb.c -o 9-print_comb $ ./9-print_comb | cat -e 0, 1, 2, 3, 4, 5, 6, 7, 8, 9$
-
100-print_comb3.c:
100-print_comb3.c - C program that prints all possible combinations of two digits, avoiding repetition and certain patterns.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 100-print_comb3.c -o 100-print_comb3 $ ./100-print_comb3 01, 02, 03, 04, 05, 06, 07, 08, 09, 12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89
-
101-print_comb4.c:
101-print_comb4.c - C program that prints all possible combinations of three digits, avoiding repetition and certain patterns.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 101-print_comb4.c -o 101-print_comb4 $ ./101-print_comb4 012, 013, 014, 015, 016, 017, 018, 019, 023, 024, 025, 026, 027, 028, 029, 034, 035, 036, 037, 038, 039, 045, 046, 047, 048, 049, 056, 057, 058, 059, 067, 068, 069, 078, 079, 089, 123, 124, 125, 126, 127, 128, 129, 134, 135, 136, 137, 138, 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168, 169, 178, 179, 189, 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249, 256, 257, 258, 259, 267, 268, 269, 278, 279, 289, 345, 346, 347, 348, 349, 356, 357, 358, 359, 367, 368, 369, 378, 379, 389, 456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789
-
102-print_comb5.c:
102-print_comb5.c - C program that prints all possible combinations of two two-digit numbers.
Test Cases:$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 102-print_comb5.c -o 102-print_comb5 $ ./102-print_comb5 00 01, 00 02, 00 03, ..., 98 99
To compile and run the C programs in this directory, follow these steps:
-
Ensure you have a C compiler (such as gcc) installed on your computer.
-
Open your terminal and navigate to the 0x01-variables_if_else_while directory.
-
Choose the file you want to compile:
-
Use the following command to compile a C file (replace
<filename.c>
with the name of the C file you want to compile):gcc <filename.c> -o <output_file>
-
Use the following command to run the compiled program (replace
<output_file>
with the name of the compiled output file):./<output_file>
-
-
After successful compilation and execution, you will see the output of the program.
Remember, success comes from genuine effort. You must avoid plagiarism and adhere to the academic integrity standards. Plagiarism is strictly forbidden and will lead to severe consequences, including removal from the program.
👤 Destiny Saturday (DestinedCodes)**
📧 Email: [email protected]
For more in-depth insights and comprehensive details about C variables, conditions, and loops, I've prepared a compelling blog post that explores these fundamental concepts. In the blog post, you'll uncover practical examples, tips, and real-world applications of these programming essentials. Whether you're a beginner seeking a deeper understanding or an experienced programmer looking for valuable insights, this blog post has something for you.
Explore the C Programming 101 Blog Post now and unlock the keys to mastering these crucial concepts in C programming!
Note: This project advances your understanding of C programming by exploring variables, conditional statements, and loops. Remember, practice is key to mastering programming concepts. Enjoy your learning journey! 🚀