Examples
This section provides various example programs written in the Lipi programming language to help you understand how to use the language features in practice.
Hello, World!
A simple program that prints "Namaste, Vishwa!" (Hello, World!) to the console.
bhana("Namaste, Vishwa!");Simple Calculator
A program that performs basic arithmetic operations (addition, subtraction, multiplication, division) based on user input.
purna choice;
purna num1;
purna num2;
purna result;
bhana("Simple Calculator");
bhana("1. Addition");
bhana("2. Subtraction");
bhana("3. Multiplication");
bhana("4. Division");
bhana("Enter your choice (1-4): ");
suna(choice);
bhana("Enter first number: ");
suna(num1);
bhana("Enter second number: ");
suna(num2);
yadi(choice == 1) {
result = num1 + num2;
bhana("Result: ");
bhana(result);
}anyatha yadi(choice == 2) {
result = num1 - num2;
bhana("Result: ");
bhana(result);
}anyatha yadi(choice == 3) {
result = num1 * num2;
bhana("Result: ");
bhana(result);
}anyatha yadi(choice == 4) {
yadi(num2 == 0) {
bhana("Error: Division by zero");
}anyatha {
result = num1 / num2;
bhana("Result: ");
bhana(result);
}
}anyatha {
bhana("Invalid choice");
}Factorial Calculator
A program that calculates the factorial of a number using recursion.
kaam purna factorial(purna n) {
yadi(n <= 1) {
firta 1;
}
firta n * factorial(n - 1);
}
purna num;
purna result;
bhana("Enter a number: ");
suna(num);
yadi(num < 0) {
bhana("Factorial is not defined for negative numbers");
}anyatha {
result = factorial(num);
bhana("Factorial of ");
bhana(num);
bhana(" is ");
bhana(result);
}Prime Number Checker
A program that checks whether a number is prime or not.
purna num;
purna i;
purna isPrime;
bhana("Enter a number: ");
suna(num);
yadi(num <= 1) {
bhana("Not a prime number");
}anyatha {
isPrime = thik;
lagi(i = 2; i * i <= num; i = i + 1;) {
yadi(num % i == 0) {
isPrime = bethik;
}
}
yadi(isPrime) {
bhana(num);
bhana(" is a prime number");
}anyatha {
bhana(num);
bhana(" is not a prime number");
}
}More Examples
For additional examples and sample programs, please refer to the examples folder in the Lipi repository. The examples folder contains various scripts and example programs written in Lipi that demonstrate different features and functionalities of the language. You can explore these examples to see how Lipi can be applied in real-world scenarios.