UDogg/ziggy
Learning Zig by writing simple but optimized programs
The calc.zig
program is a simple calculator application written in the Zig programming language. It allows you to perform basic arithmetic operations such as addition, subtraction, multiplication, division, and quotient(integer) division all in one. The program takes two user-provided integer inputs and then displays the results of these operations.
Zig Downloads
Follow these steps to run the calc.zig
program:
Open a Terminal: Open a terminal window that you are comfortable with on your computer.
Navigate to Program Directory: Use the cd
command to navigate to the directory where the calc.zig
file is located.
Compile the Program: In the terminal, enter the following command to compile the program:
zig build-exe calc.zig
Run the Program: After successful compilation, run the compiled executable by typing:
./calc
$ zig build-exe calc.zig
$ ./calc
Enter a number: 10
Enter another number: 5
The sum of 10 and 5 is 15
The difference of 10 and 5 is 5
The product of 10 and 5 is 50
The quotient of 10 and 5 is 2
The division of 10 and 5 produces 2.000000
Execution time(depends on your typing speed and time you took to enter numbers): 600 ms
The prime.zig
program is designed to work with prime numbers. It offers functionalities to check if a given number is prime, find the nth prime number, print the first N prime numbers, and find the position of a specific prime number in the sequence of all prime numbers. The program uses a variety of functions and logic to achieve these tasks.
Zig Downloads
Follow these steps to run the prime.zig
program:
Open a Terminal: Open a terminal window that you are comfortable with on your computer.
Navigate to Program Directory: Use the cd
command to navigate to the directory where the prime.zig
file is located.
Compile the Program: In the terminal, enter the following command to compile the program:
zig build-exe prime.zig
./prime
$ zig build-exe prime.zig
$ ./prime
Enter the number of prime numbers you want to print: 5
Enter the value of N (Nth prime number you wish to print): 3
Enter a prime number to find its position: 7
The first 5 prime numbers are: 2, 3, 5, 7, 11
The 3rd prime number is: 5
The position of 7 in the set of all prime numbers is 4
Total execution time: 0 milliseconds
Feel free to experiment with different input values and explore the program's functionalities!
In development freecodecamp guy
In development
Written with ❤️ and Ziglang
Written by
Utkarsh "UC" Choudhary