Example Programs

Learn Odialang through hands-on examples. From Hello World to complex algorithms.

Basics

Basics
01 Hello

Example 1: Hello World

# Example 1: Hello World
# The most basic program - prints a greeting

# Print a simple message
dekha "Hello, World!"

# Print in Odia
dekha "Namaskar, Odia!"

# Print multiple lines
dekha "Welcome to"
dekha "Odialang!"

# Output:
# Hello, World!
# Namaskar, Odia!
# Welcome to
# Odialang!
Open in Playground
Basics
02 Variables

Example 2: Variables

# Example 2: Variables
# Learn about different data types

# String variable (text)
dhara name = "Rama"
dhara greeting = "Hello"
dekha greeting + " " + name

# Number variables
dhara age = 25
dhara year = 2026
dhara bigNumber = 1000
dekha "Age: " + age
dekha "Year: " + year
dekha "Big number: " + bigNumber

# Boolean variables (true/false)
dhara isStudent = sata
dhara isWorking = micha
dekha "Is student: " + isStudent
dekha "Is working: " + isWorking

# Changing variable values
dhara score = 0
dekha "Initial score: " + score

score = 10
dekha "After assignment: " + score

score = score + 5
dekha "After adding 5: " + score

# Output:
# Hello Rama
# Age: 25
# Year: 2026
# Big number: 1000
# Is student: true
# Is working: false
# Initial score: 0
# After assignment: 10
# After adding 5: 15
Open in Playground
Basics
03 Operators

Example 3: Operators

# Example 3: Operators
# Arithmetic and comparison operations

dhara a = 10
dhara b = 3

# Arithmetic operators
dekha "=== Arithmetic Operators ==="
dekha "a = " + a + ", b = " + b
dekha "Addition: " + a + " + " + b + " = " + (a + b)
dekha "Subtraction: " + a + " - " + b + " = " + (a - b)
dekha "Multiplication: " + a + " * " + b + " = " + (a * b)
dekha "Division: " + a + " / " + b + " = " + (a / b)

# String concatenation
dekha ""
dekha "=== String Concatenation ==="
dhara first = "Hello"
dhara second = "World"
dekha first + " " + second + "!"

# Comparison operators
dekha ""
dekha "=== Comparison Operators ==="
dekha "a > b: " + (a > b)
dekha "a < b: " + (a < b)
dekha "a == b: " + (a == b)
dekha "a != b: " + (a != b)
dekha "a >= b: " + (a >= b)
dekha "a <= b: " + (a <= b)

# Equal values
dhara x = 5
dhara y = 5
dekha ""
dekha "x = " + x + ", y = " + y
dekha "x == y: " + (x == y)

# Output:
# === Arithmetic Operators ===
# a = 10, b = 3
# Addition: 10 + 3 = 13
# Subtraction: 10 - 3 = 7
# Multiplication: 10 * 3 = 30
# Division: 10 / 3 = 3.333...
# 
# === String Concatenation ===
# Hello World!
#
# === Comparison Operators ===
# a > b: true
# a < b: false
# a == b: false
# a != b: true
# a >= b: true
# a <= b: false
#
# x = 5, y = 5
# x == y: true
Open in Playground
Basics
04 Conditionals

Example 4: Conditionals (If-Else)

# Example 4: Conditionals (If-Else)
# Making decisions in your program

# Simple if statement
dhara age = 18
dekha "Age: " + age

jadi age >= 18 tahale
  dekha "You are an adult"
sesa

# If-else statement
dekha ""
dhara marks = 75
dekha "Marks: " + marks

jadi marks >= 60 tahale
  dekha "Result: PASSED"
nahele
  dekha "Result: FAILED"
sesa

# Multiple conditions
dekha ""
dhara score = 85
dekha "Score: " + score

jadi score >= 90 tahale
  dekha "Grade: A"
sesa

jadi score >= 80 tahale
  dekha "Grade: B"
sesa

jadi score >= 70 tahale
  dekha "Grade: C"
nahele
  dekha "Grade: F"
sesa

# Check if number is positive or not
dekha ""
dhara number = 7
dekha "Number: " + number

jadi number > 0 tahale
  dekha "The number is positive"
sesa

jadi number < 0 tahale
  dekha "The number is negative"
sesa

jadi number == 0 tahale
  dekha "The number is zero"
sesa

# Output:
# Age: 18
# You are an adult
# 
# Marks: 75
# Result: PASSED
#
# Score: 85
# Grade: B
#
# Number: 7
# The number is positive
Open in Playground
Basics
05 While Loop

Example 5: While Loop

# Example 5: While Loop
# Repeat actions with conditions

# Count from 1 to 5
dekha "=== Counting 1 to 5 ==="
dhara count = 1

jebe count <= 5
  dekha "Count: " + count
  count += 1
sesa

# Countdown
dekha ""
dekha "=== Countdown ==="
dhara timer = 5

jebe timer > 0
  dekha "Time: " + timer
  timer -= 1
sesa

dekha "Blast off!"

# Sum of numbers 1 to 10
dekha ""
dekha "=== Sum of 1 to 10 ==="
dhara sum = 0
dhara num = 1

jebe num <= 10
  sum += num
  num += 1
sesa

dekha "Sum = " + sum

# Print numbers doubled
dekha ""
dekha "=== Numbers doubled 1 to 10 ==="
dhara i = 1

jebe i <= 10
  dekha i + " x 2 = " + (i * 2)
  i += 1
sesa
Open in Playground
Basics
06 For Loop

Example 6: For Loop

# Example 6: For Loop
# Iterate with range

# Print 1 to 5
dekha "=== Print 1 to 5 ==="
aarambha i = 1 ru 5
  dekha "Number: " + i
sesa

# Countdown 5 to 1
dekha ""
dekha "=== Countdown 5 to 1 ==="
aarambha j = 5 ru 1
  dekha j
sesa

# Multiplication table
dekha ""
dekha "=== Multiplication Table of 7 ==="
dhara table = 7

aarambha k = 1 ru 10
  dekha table + " x " + k + " = " + (table * k)
sesa

# Sum using for loop
dekha ""
dekha "=== Sum of 1 to 100 ==="
dhara total = 0

aarambha n = 1 ru 100
  total += n
sesa

dekha "Total: " + total

# Print squares
dekha ""
dekha "=== Squares of 1 to 10 ==="
aarambha num = 1 ru 10
  dekha num + "^2 = " + (num * num)
sesa
Open in Playground
Basics
07 Strings

String Operations

# String Operations
# Learn about working with text in Odialang

# Basic string concatenation
dhara firstName = "Rama"
dhara lastName = "Das"
dhara fullName = firstName + " " + lastName
dekha "Name: " + fullName

# String with numbers
dhara age = 25
dekha "Age: " + age

# String multiplication (repeat)
dhara line = "-"
dhara border = line + line + line + line + line
dekha border
dekha "| Welcome |"
dekha border

# Multi-line strings
dhara poem = "ଓଡ଼ିଆ ଭାଷା
ଓଡ଼ିଆ ଭାଷା ଅତି ପ୍ରାଚୀନ
ଏହା ଭାରତର ରତ୍ନ"
dekha poem

# String with escape sequences
dhara quote = "He said \"Namaste\" to everyone"
dekha quote

dhara path = "C:\\Users\\Documents"
dekha "Path: " + path

# String concatenation chain
dekha "Hello" + ", " + "World" + "!"

# Output:
# Name: Rama Das
# Age: 25
# -----
# | Welcome |
# -----
# ଓଡ଼ିଆ ଭାଷା ଅତି ପ୍ରାଚୀନ...
# He said "Namaste" to everyone
# Path: C:\Users\Documents
# Hello, World!
Open in Playground
Basics
08 Math

Math Operations

# Math Operations
# Advanced mathematical operations in Odialang

# Basic arithmetic
dekha "=== Basic Math ==="
dhara a = 10
dhara b = 3
dekha "a = " + a + ", b = " + b
dekha "a + b = " + (a + b)
dekha "a - b = " + (a - b)
dekha "a * b = " + (a * b)
dekha "a / b = " + (a / b)
dekha "a % b = " + (a % b)

# Decimal numbers
dekha ""
dekha "=== Decimal Math ==="
dhara pi = 3.14159
dhara radius = 5
dhara area = pi * radius * radius
dekha "Circle area (r=" + radius + "): " + area

dhara e = 2.71828
dekha "e = " + e

# Negative numbers
dekha ""
dekha "=== Negative Numbers ==="
dhara x = -5
dhara y = -10
dekha "x = " + x
dekha "y = " + y
dekha "-x = " + (-x)
dekha "-y = " + (-y)
dekha "x + y = " + (x + y)

# Absolute value (manual)
karya abs(n)
  jadi n < 0 tahale
    dhara result = 0 - n
    dekha "abs(" + n + ") = " + result
  nahele
    dekha "abs(" + n + ") = " + n
  sesa
sesa

dekha ""
dekha "=== Absolute Value ==="
abs(-42)
abs(25)
abs(0)
abs(-100)

# Power calculation
karya power(base, exp)
  dhara result = 1
  dhara i = 0
  jebe i < exp
    result = result * base
    i = i + 1
  sesa
  dekha base + "^" + exp + " = " + result
sesa

dekha ""
dekha "=== Powers ==="
power(2, 10)
power(3, 4)
power(5, 3)

# Output:
# === Basic Math ===
# a = 10, b = 3
# a + b = 13
# a - b = 7
# a * b = 30
# a / b = 3.333...
# a % b = 1
# === Decimal Math ===
# Circle area (r=5): 78.53975
# e = 2.71828
# === Negative Numbers ===
# x = -5
# y = -10
# -x = 5
# -y = 10
# x + y = -15
# === Absolute Value ===
# abs(-42) = 42
# abs(25) = 25
# abs(0) = 0
# === Powers ===
# 2^10 = 1024
# 3^4 = 81
# 5^3 = 125
Open in Playground

Intermediate

Intermediate
01 Functions

Example 1: Functions

# Example 1: Functions
# Reusable blocks of code

# Simple function without parameters
karya sayHello()
  dekha "Hello from function!"
sesa

# Call the function
dekha "=== Calling sayHello() ==="
sayHello()
sayHello()

# Function with parameters
karya greet(name)
  dekha "Namaskar, " + name + "!"
sesa

dekha ""
dekha "=== Greeting people ==="
greet("Rama")
greet("Sita")
greet("Hari")

# Function with multiple parameters
karya introduce(name, age, city)
  dekha "Name: " + name
  dekha "Age: " + age
  dekha "City: " + city
  dekha "---"
sesa

dekha ""
dekha "=== Introductions ==="
introduce("Rama", 25, "Bhubaneswar")
introduce("Sita", 23, "Cuttack")

# Function that returns a value
karya add(a, b)
  fera a + b
sesa

dekha ""
dekha "=== Addition function ==="
dhara result1 = add(10, 20)
dekha "10 + 20 = " + result1

dhara result2 = add(5, 7)
dekha "5 + 7 = " + result2

# Using function result directly
dekha "100 + 200 = " + add(100, 200)

# Function with calculation
dekha ""
dekha "=== Rectangle Area ==="
karya rectangleArea(length, width)
  fera length * width
sesa

dhara area = rectangleArea(10, 5)
dekha "Area of rectangle (10 x 5): " + area

# Output:
# === Calling sayHello() ===
# Hello from function!
# Hello from function!
#
# === Greeting people ===
# Namaskar, Rama!
# Namaskar, Sita!
# Namaskar, Hari!
#
# === Introductions ===
# Name: Rama
# Age: 25
# City: Bhubaneswar
# ---
# Name: Sita
# Age: 23
# City: Cuttack
# ---
#
# === Addition function ===
# 10 + 20 = 30
# 5 + 7 = 12
# 100 + 200 = 300
#
# === Rectangle Area ===
# Area of rectangle (10 x 5): 50
Open in Playground
Intermediate
02 Recursion

Example 2: Recursion

# Example 2: Recursion
# Functions that call themselves

# Factorial: n! = n * (n-1) * (n-2) * ... * 1
# Example: 5! = 5 * 4 * 3 * 2 * 1 = 120
karya factorial(n)
  # Base case: factorial of 0 or 1 is 1
  jadi n <= 1 tahale
    fera 1
  sesa
  
  # Recursive case: n! = n * (n-1)!
  fera n * factorial(n - 1)
sesa

dekha "=== Factorial ==="
dekha "5! = " + factorial(5)
dekha "3! = " + factorial(3)
dekha "7! = " + factorial(7)

# Power calculation: base^exponent
# Example: 2^3 = 2 * 2 * 2 = 8
karya power(base, exponent)
  # Base case: anything^0 = 1
  jadi exponent == 0 tahale
    fera 1
  sesa
  
  # Recursive case: base^exp = base * base^(exp-1)
  fera base * power(base, exponent - 1)
sesa

dekha ""
dekha "=== Power ==="
dekha "2^3 = " + power(2, 3)
dekha "5^2 = " + power(5, 2)
dekha "3^4 = " + power(3, 4)

# Countdown using recursion
karya countdown(n)
  jadi n > 0 tahale
    dekha n
    countdown(n - 1)
  sesa
sesa

dekha ""
dekha "=== Countdown (5 to 1) ==="
countdown(5)

# Output:
# === Factorial ===
# 5! = 120
# 3! = 6
# 7! = 5040
#
# === Power ===
# 2^3 = 8
# 5^2 = 25
# 3^4 = 81
#
# === Countdown (5 to 1) ===
# 5
# 4
# 3
# 2
# 1
#
# === Sum of Digits ===
# Sum of digits in 123: 6
# Sum of digits in 4567: 22
Open in Playground
Intermediate
03 Calculator

Example 3: Calculator

# Example 3: Calculator
# A functional calculator program

# Addition function
karya add(a, b)
  fera a + b
sesa

# Subtraction function
karya subtract(a, b)
  fera a - b
sesa

# Multiplication function
karya multiply(a, b)
  fera a * b
sesa

# Division function
karya divide(a, b)
  jadi b == 0 tahale
    dekha "Error: Cannot divide by zero!"
    fera 0
  sesa
  fera a / b
sesa

# Display calculator menu
karya showMenu()
  dekha ""
  dekha "=== CALCULATOR ==="
  dekha "1. Add"
  dekha "2. Subtract"
  dekha "3. Multiply"
  dekha "4. Divide"
  dekha "================"
sesa

# Calculate and display result
karya calculate(num1, num2, operation)
  jadi operation == "add" tahale
    fera add(num1, num2)
  sesa
  
  jadi operation == "subtract" tahale
    fera subtract(num1, num2)
  sesa
  
  jadi operation == "multiply" tahale
    fera multiply(num1, num2)
  sesa
  
  jadi operation == "divide" tahale
    fera divide(num1, num2)
  sesa
  
  dekha "Unknown operation"
  fera 0
sesa

# Main program
dekha "=== Simple Calculator Demo ==="
dhara x = 15
dhara y = 5

showMenu()

dekha ""
dekha "Numbers: " + x + " and " + y
dekha ""

dekha "Addition: " + x + " + " + y + " = " + calculate(x, y, "add")
dekha "Subtraction: " + x + " - " + y + " = " + calculate(x, y, "subtract")
dekha "Multiplication: " + x + " * " + y + " = " + calculate(x, y, "multiply")
dekha "Division: " + x + " / " + y + " = " + calculate(x, y, "divide")

# Test division by zero
dekha ""
dekha "=== Testing Division by Zero ==="
calculate(10, 0, "divide")

# Output:
# === Simple Calculator Demo ===
# 
# === CALCULATOR ===
# 1. Add
# 2. Subtract
# 3. Multiply
# 4. Divide
# ================
# 
# Numbers: 15 and 5
# 
# Addition: 15 + 5 = 20
# Subtraction: 15 - 5 = 10
# Multiplication: 15 * 5 = 75
# Division: 15 / 5 = 3
# 
# === Testing Division by Zero ===
# Error: Cannot divide by zero!
Open in Playground
Intermediate
04 Temperature

Example 4: Number Utilities

# Example 4: Number Utilities
# Various number manipulation functions

# Calculate square
karya square(n)
  fera n * n
sesa

# Calculate cube
karya cube(n)
  fera n * n * n
sesa

# Calculate sum of squares from 1 to n
karya sumOfSquares(n)
  dhara sum = 0
  dhara i = 1
  
  jebe i <= n
    dhara sq = square(i)
    sum = sum + sq
    i = i + 1
  sesa
  
  fera sum
sesa

# Calculate average
karya average(a, b, c)
  dhara total = a + b + c
  fera total / 3
sesa

# Display results
dekha "=== NUMBER UTILITIES ==="
dekha ""

# Test squares
dekha "=== Squares ==="
dekha "Square of 5: " + square(5)
dekha "Square of 10: " + square(10)
dekha "Square of 12: " + square(12)

# Test cubes
dekha ""
dekha "=== Cubes ==="
dekha "Cube of 3: " + cube(3)
dekha "Cube of 5: " + cube(5)
dekha "Cube of 7: " + cube(7)

# Test sum of squares
dekha ""
dekha "=== Sum of Squares ==="
dekha "Sum of squares 1 to 5: " + sumOfSquares(5)
dekha "Sum of squares 1 to 10: " + sumOfSquares(10)

# Test average
dekha ""
dekha "=== Average ==="
dekha "Average of 10, 20, 30: " + average(10, 20, 30)
dekha "Average of 75, 85, 95: " + average(75, 85, 95)

# Combined example
dekha ""
dekha "=== Combined Example ==="
dhara num = 6
dhara sq = square(num)
dhara cb = cube(num)
dhara sumSq = sumOfSquares(num)

dekha "Number: " + num
dekha "Square: " + sq
dekha "Cube: " + cb
dekha "Sum of squares 1 to " + num + ": " + sumSq

# Output:
# === NUMBER UTILITIES ===
# 
# === Squares ===
# Square of 5: 25
# Square of 10: 100
# Square of 12: 144
#
# === Cubes ===
# Cube of 3: 27
# Cube of 5: 125
# Cube of 7: 343
#
# === Sum of Squares ===
# Sum of squares 1 to 5: 55
# Sum of squares 1 to 10: 385
#
# === Average ===
# Average of 10, 20, 30: 20
# Average of 75, 85, 95: 85
#
# === Combined Example ===
# Number: 6
# Square: 36
# Cube: 216
# Sum of squares 1 to 6: 91
Open in Playground
Intermediate
05 Math Funcs

Mathematical Functions

# Mathematical Functions
# Common mathematical operations and algorithms

# Factorial
karya factorial(n)
  dhara result = 1
  dhara i = 2
  jebe i <= n
    result = result * i
    i = i + 1
  sesa
  fera result
sesa

# Check if number is prime
karya isPrime(n)
  jadi n <= 1 tahale
    fera micha
  sesa
  jadi n == 2 tahale
    fera sata
  sesa
  dhara i = 2
  jebe i * i <= n
    jadi n % i == 0 tahale
      fera micha
    sesa
    i = i + 1
  sesa
  fera sata
sesa

# Find GCD (Greatest Common Divisor)
karya gcd(a, b)
  jebe b != 0
    dhara temp = b
    b = a % b
    a = temp
  sesa
  fera a
sesa

# Find LCM (Least Common Multiple)
karya lcm(a, b)
  dhara g = gcd(a, b)
  dhara result = a * b / g
  fera result
sesa

dekha "=== Factorial ==="
dekha "5! = " + factorial(5)
dekha "0! = " + factorial(0)
dekha "10! = " + factorial(10)

dekha ""
dekha "=== Prime Numbers ==="
dekha "Is 7 prime? " + isPrime(7)
dekha "Is 15 prime? " + isPrime(15)
dekha "Is 2 prime? " + isPrime(2)
dekha "Is 1 prime? " + isPrime(1)

dekha ""
dekha "=== Finding Primes (1-20) ==="
dhara i = 1
jebe i <= 20
  jadi isPrime(i) tahale
    dekha i + " is prime"
  sesa
  i = i + 1
sesa

dekha ""
dekha "=== GCD and LCM ==="
dekha "GCD(48, 18) = " + gcd(48, 18)
dekha "GCD(100, 25) = " + gcd(100, 25)
dekha "LCM(4, 6) = " + lcm(4, 6)
dekha "LCM(12, 18) = " + lcm(12, 18)

# Power function
karya power(base, exp)
  dhara result = 1
  dhara j = 0
  jebe j < exp
    result = result * base
    j = j + 1
  sesa
  fera result
sesa

dekha ""
dekha "=== Power ==="
dekha "2^10 = " + power(2, 10)
dekha "3^5 = " + power(3, 5)
dekha "5^3 = " + power(5, 3)

# Fibonacci
karya fibonacci(n)
  jadi n <= 1 tahale
    fera n
  sesa
  dhara a = 0
  dhara b = 1
  dhara i = 2
  jebe i <= n
    dhara temp = a + b
    a = b
    b = temp
    i = i + 1
  sesa
  dhara result = a + b
  fera result
sesa

dekha ""
dekha "=== Fibonacci ==="
dekha "fib(0) = " + fibonacci(0)
dekha "fib(1) = " + fibonacci(1)
dekha "fib(5) = " + fibonacci(5)
dekha "fib(10) = " + fibonacci(10)

# Output:
# === Factorial ===
# 5! = 120
# 0! = 1
# 10! = 3628800
# === Prime Numbers ===
# Is 7 prime? true
# Is 15 prime? false
# === Finding Primes (1-20) ===
# 2 is prime
# 3 is prime
# 5 is prime
# 7 is prime
# 11 is prime
# 13 is prime
# 17 is prime
# 19 is prime
# === GCD and LCM ===
# GCD(48, 18) = 6
# GCD(100, 25) = 25
# LCM(4, 6) = 12
# LCM(12, 18) = 36
# === Power ===
# 2^10 = 1024
# 3^5 = 243
# 5^3 = 125
# === Fibonacci ===
# fib(0) = 0
# fib(1) = 1
# fib(5) = 5
# fib(10) = 55
Open in Playground
Intermediate
06 Scope

Variable Scope

# Variable Scope
# Understanding how variables work in different scopes

dekha "=== Global vs Local Variables ==="

# Global variable
dhara globalVar = "I am global"
dekha "Global: " + globalVar

# Function with local variable
karya testLocal()
  dhara localVar = "I am local"
  dekha "Inside function - Local: " + localVar
  dekha "Inside function - Global: " + globalVar
sesa

testLocal()

# Global variable can be accessed outside
dekha "Outside function - Global: " + globalVar

# Shadowing example
dekha ""
dekha "=== Variable Shadowing ==="

dhara counter = 0

karya increment()
  dhara counter = 100  # This shadows the global counter
  counter = counter + 1  # This modifies the local counter
  dekha "Inside increment - counter = " + counter
sesa

dekha "Before increment - counter = " + counter
increment()
dekha "After increment - counter = " + counter

# To modify global variable, don't declare with dhara
dekha ""
dekha "=== Modifying Global Variable ==="

dhara count = 0

karya incrementGlobal()
  # Modifying global (no dhara = assignment to existing)
  count = count + 1
  dekha "Incremented to: " + count
sesa

karya resetCount()
  count = 0
  dekha "Count reset to: " + count
sesa

dekha "Initial count: " + count
incrementGlobal()
incrementGlobal()
incrementGlobal()
dekha "After 3 increments: " + count
resetCount()
dekha "After reset: " + count

# Nested function scope
dekha ""
dekha "=== Nested Function Scope ==="

karya outer()
  dhara outerVar = "outer"
  dekha "In outer: " + outerVar
  
  karya inner()
    dhara innerVar = "inner"
    dekha "In inner: " + innerVar
    dekha "In inner, can see: " + outerVar
  sesa
  
  inner()
  # This would error: dekha innerVar
sesa

outer()

# Output:
# === Global vs Local Variables ===
# Global: I am global
# Inside function - Local: I am local
# Inside function - Global: I am global
# Outside function - Global: I am global
# === Variable Shadowing ===
# Before increment - counter = 0
# Inside increment - counter = 101
# After increment - counter = 0
# === Modifying Global Variable ===
# Initial count: 0
# Incremented to: 1
# Incremented to: 2
# Incremented to: 3
# After 3 increments: 3
# After reset: 0
# === Nested Function Scope ===
# In outer: outer
# In inner: inner
# In inner, can see: outer
Open in Playground
Intermediate
07 Arrays

Example 7: Arrays

# Example 7: Arrays
# Working with lists of data

# Creating arrays
dhara nums = [10, 20, 30, 40, 50]
dekha "Numbers: " + nums

# Accessing elements by index
dekha "First: " + nums[0]
dekha "Third: " + nums[2]
dekha "Last: " + nums[4]

# Array length
dekha "Length: " + nums.length

# Modifying array elements
dekha ""
dekha "=== Modifying Arrays ==="
dhara scores = [85, 92, 78, 95, 88]
dekha "Original scores: " + scores
scores[0] = 90
scores[2] = 82
dekha "Updated scores: " + scores

# Arrays with strings
dhara names = ["Rama", "Sita", "Hari"]
dekha "Names: " + names
dekha "Second name: " + names[1]

# Indexing in loops
dekha ""
dekha "=== Looping Through Arrays ==="
aarambha i = 0 ru 4
  dekha "nums[" + i + "] = " + nums[i]
sesa

# Nested arrays
dekha ""
dekha "=== Nested Arrays ==="
dhara matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
dekha "Row 0: " + matrix[0]
dekha "Row 1: " + matrix[1]
dekha "Element [0][0]: " + matrix[0][0]
dekha "Element [1][2]: " + matrix[1][2]

# Compound assignment on array elements
dhara data = [100, 200, 300]
dekha ""
dekha "Original: " + data
data[1] += 50
data[0] -= 10
dekha "After += and -=: " + data

# Empty array
dhara empty = []
dekha ""
dekha "Empty array: " + empty
Open in Playground

Advanced

Advanced
01 Fizzbuzz

Example 1: FizzBuzz

# Example 1: FizzBuzz
# Classic programming interview question
# Using logical operators (&&) and modulo (%)

karya fizzBuzz(n)
  jadi n % 3 == 0 && n % 5 == 0 tahale
    dekha "FizzBuzz"
  sesa

  jadi n % 3 == 0 tahale
    dekha "Fizz"
  sesa

  jadi n % 5 == 0 tahale
    dekha "Buzz"
  sesa

  jadi n % 3 != 0 && n % 5 != 0 tahale
    dekha n
  sesa
sesa

# Print FizzBuzz for 1-20
dekha "=== FizzBuzz ==="
aarambha i = 1 ru 20
  fizzBuzz(i)
sesa
Open in Playground
Advanced
02 Prime

Example 2: Multiplication Tables

# Example 2: Multiplication Tables
# Generate multiplication tables

# Function to print a multiplication table
karya printTable(number, limit)
  dekha ""
  dekha "=== Table of " + number + " ==="
  
  aarambha i = 1 ru limit
    dekha number + " x " + i + " = " + (number * i)
  sesa
sesa

# Function to compare tables
karya compareTables(a, b, limit)
  dekha ""
  dekha "=== Comparing tables of " + a + " and " + b + " ==="
  
  aarambha i = 1 ru limit
    dhara productA = a * i
    dhara productB = b * i
    dhara diff = productA - productB
    
    dekha a + "x" + i + "=" + productA + " | " + b + "x" + i + "=" + productB + " | Diff=" + diff
  sesa
sesa

# Function to find squares using multiplication
karya findSquares(limit)
  dekha ""
  dekha "=== Squares (1 to " + limit + ") ==="
  
  aarambha i = 1 ru limit
    dhara square = i * i
    dekha i + "² = " + square
  sesa
sesa

# Main program
dekha "=== MULTIPLICATION TABLES ==="

# Print tables for 2 through 10
printTable(2, 10)
printTable(5, 10)
printTable(9, 10)

# Compare tables
compareTables(6, 7, 10)

# Find squares
findSquares(15)

# Challenge: Find the table that sums to exactly 100
# (Hint: It's table of 4 up to 10: 4+8+12+16+20+24+28+32+36+40 = 220)
# Actually let's calculate
dekha ""
dekha "=== Sum of table entries ==="

aarambha tableNum = 2 ru 10
  dhara sum = 0
  
  aarambha i = 1 ru 10
    sum = sum + (tableNum * i)
  sesa
  
  dekha "Sum of table " + tableNum + " (1 to 10): " + sum
sesa

# Output:
# === MULTIPLICATION TABLES ===
# 
# === Table of 2 ===
# 2 x 1 = 2
# 2 x 2 = 4
# ...
# 
# === Comparing tables of 6 and 7 ===
# 6x1=6 | 7x1=7 | Diff=-1
# 6x2=12 | 7x2=14 | Diff=-2
# ...
#
# === Squares (1 to 15) ===
# 1² = 1
# 2² = 4
# ...
#
# === Sum of table entries ===
# Sum of table 2 (1 to 10): 110
# Sum of table 3 (1 to 10): 165
# ...
Open in Playground
Advanced
03 Fibonacci

Example 3: Fibonacci Series

# Example 3: Fibonacci Series
# The famous number sequence

# Fibonacci: Each number is the sum of the two preceding ones
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

# Print first N Fibonacci numbers
dekha "=== FIBONACCI SERIES ==="
dekha ""

# Method 1: Using iteration
dekha "First 15 Fibonacci numbers:"
dhara first = 0
dhara second = 1
dhara n = 15
dhara count = 0

dekha first
dekha second

aarambha i = 3 ru n
  dhara next = first + second
  dekha next
  first = second
  second = next
sesa

# Method 2: Using a function
karya fibonacci(n)
  jadi n <= 0 tahale
    fera 0
  sesa
  
  jadi n == 1 tahale
    fera 1
  sesa
  
  dhara a = 0
  dhara b = 1
  dhara result = 0
  
  aarambha i = 2 ru n
    result = a + b
    a = b
    b = result
  sesa
  
  fera result
sesa

dekha ""
dekha "=== Fibonacci using function ==="
dekha "fib(0) = " + fibonacci(0)
dekha "fib(5) = " + fibonacci(5)
dekha "fib(10) = " + fibonacci(10)
dekha "fib(15) = " + fibonacci(15)

# Calculate sum of Fibonacci series
dekha ""
dekha "=== Sum of first 10 Fibonacci numbers ==="
dhara sum = 0

aarambha i = 0 ru 9
  sum = sum + fibonacci(i)
sesa

dekha "Sum = " + sum

# Golden ratio approximation
dekha ""
dekha "=== Golden Ratio Approximation ==="
dekha "Ratio of consecutive Fibonacci numbers:"

aarambha i = 10 ru 20
  dhara current = fibonacci(i)
  dhara previous = fibonacci(i - 1)
  dhara ratio = current / previous
  dekha "F(" + i + ") / F(" + (i - 1) + ") = " + ratio
sesa

# Output:
# === FIBONACCI SERIES ===
# 
# First 15 Fibonacci numbers:
# 0
# 1
# 1
# 2
# 3
# 5
# 8
# 13
# 21
# 34
# 55
# 89
# 144
# 233
# 377
#
# === Fibonacci using function ===
# fib(0) = 0
# fib(5) = 5
# fib(10) = 55
# fib(15) = 610
#
# === Sum of first 10 Fibonacci numbers ===
# Sum = 143
#
# === Golden Ratio Approximation ===
# Ratio of consecutive Fibonacci numbers:
# F(10) / F(9) = 1.617...
# ...
Open in Playground
Advanced
04 Factorial

Example 4: Factorial Calculator

# Example 4: Factorial Calculator
# Calculate factorial using different methods

# Method 1: Iterative approach
karya factorialIterative(n)
  jadi n < 0 tahale
    fera 0
  sesa
  
  jadi n == 0 tahale
    fera 1
  sesa
  
  dhara result = 1
  
  aarambha i = 1 ru n
    result = result * i
  sesa
  
  fera result
sesa

# Method 2: Recursive approach
karya factorialRecursive(n)
  # Base case
  jadi n <= 1 tahale
    fera 1
  sesa
  
  # Recursive case
  fera n * factorialRecursive(n - 1)
sesa

# Display factorials
dekha "=== FACTORIAL CALCULATOR ==="
dekha ""

# Calculate factorials 0 to 10
dekha "Factorials (0 to 10):"
dekha ""

dekha "Iterative method:"
aarambha i = 0 ru 10
  dekha i + "! = " + factorialIterative(i)
sesa

dekha ""
dekha "Recursive method:"
aarambha i = 0 ru 10
  dekha i + "! = " + factorialRecursive(i)
sesa

# Compare methods
dekha ""
dekha "=== Verification ==="
dekha "Both methods give same results: "

dhara same = sata
aarambha i = 0 ru 10
  jadi factorialIterative(i) != factorialRecursive(i) tahale
    same = micha
  sesa
sesa

jadi same tahale
  dekha "YES - Results match!"
nahele
  dekha "NO - There's a bug!"
sesa

# Large factorial
dekha ""
dekha "=== Large Factorials ==="
dekha "15! = " + factorialIterative(15)
dekha "20! = " + factorialIterative(20)

# Factorial properties demonstration
dekha ""
dekha "=== Factorial Properties ==="
# n! = n * (n-1)!
dhara n = 8
dhara factN = factorialIterative(n)
dhara factNMinus1 = factorialIterative(n - 1)
dekha n + "! = " + factN
dekha (n - 1) + "! = " + factNMinus1
dekha n + " * " + (n - 1) + "! = " + (n * factNMinus1)
dekha "Verification: " + factN + " == " + (n * factNMinus1)

# Sum of factorials
dekha ""
dekha "=== Sum of Factorials (1! + 2! + ... + 5!) ==="
dhara sum = 0
aarambha i = 1 ru 5
  sum = sum + factorialIterative(i)
sesa
dekha "Sum = " + sum

# Output:
# === FACTORIAL CALCULATOR ===
# 
# Factorials (0 to 10):
# 
# Iterative method:
# 0! = 1
# 1! = 1
# 2! = 2
# 3! = 6
# 4! = 24
# 5! = 120
# 6! = 720
# 7! = 5040
# 8! = 40320
# 9! = 362880
# 10! = 3628800
# 
# Recursive method:
# [Same output]
#
# === Verification ===
# Both methods give same results: YES - Results match!
#
# === Large Factorials ===
# 15! = 1307674368000
# 20! = 2432902008176640000
#
# === Factorial Properties ===
# 8! = 40320
# 7! = 5040
# 8 * 7! = 40320
# Verification: 40320 == 40320
#
# === Sum of Factorials (1! + 2! + ... + 5!) ===
# Sum = 153
Open in Playground
Advanced
05 Grade Calculator

Example 5: Grade Calculator

# Example 5: Grade Calculator
# Complete student grading system with logical operators

# Function to calculate grade based on marks
karya calculateGrade(marks)
  jadi marks >= 90 tahale
    fera "A+"
  sesa
  
  jadi marks >= 80 tahale
    fera "A"
  sesa
  
  jadi marks >= 70 tahale
    fera "B"
  sesa
  
  jadi marks >= 60 tahale
    fera "C"
  sesa
  
  jadi marks >= 50 tahale
    fera "D"
  sesa
  
  fera "F"
sesa

# Function to check pass/fail using logical AND (&&)
karya hasPassed(m1, m2, m3, m4, m5)
  jadi m1 >= 50 && m2 >= 50 && m3 >= 50 && m4 >= 50 && m5 >= 50 tahale
    fera sata
  nahele
    fera micha
  sesa
sesa

# Calculate total and average
karya calcAverage(m1, m2, m3, m4, m5)
  dhara total = m1 + m2 + m3 + m4 + m5
  fera total / 5
sesa

# Student 1: Excellent performance
dekha "========================================"
dekha "          STUDENT REPORT CARD"
dekha "========================================"
dhara name1 = "Rama Das"
dhara m1 = 92
dhara m2 = 88
dhara m3 = 85
dhara m4 = 90
dhara m5 = 87
dhara avg1 = calcAverage(m1, m2, m3, m4, m5)
dekha "Name: " + name1
dekha "Average: " + avg1 + "%"
dekha "Overall Grade: " + calculateGrade(avg1)
dekha "All subjects passed: " + hasPassed(m1, m2, m3, m4, m5)
dekha "========================================"

# Student 2: Failed in one subject
dekha ""
dekha "========================================"
dekha "          STUDENT REPORT CARD"
dekha "========================================"
dhara name2 = "Gita Mohanty"
dhara s1 = 45
dhara s2 = 78
dhara s3 = 82
dhara s4 = 75
dhara s5 = 80
dhara avg2 = calcAverage(s1, s2, s3, s4, s5)
dekha "Name: " + name2
dekha "Average: " + avg2 + "%"
dekha "Overall Grade: " + calculateGrade(avg2)
dekha "All subjects passed: " + hasPassed(s1, s2, s3, s4, s5)
dekha "========================================"

# Class statistics using logical operators
dekha ""
dekha "=== CLASS STATISTICS ==="
dhara totalStudents = 4
dhara passCount = 3
dhara failCount = 1
dhara passPercentage = (passCount * 100) / totalStudents
dekha "Total Students: " + totalStudents
dekha "Passed: " + passCount
dekha "Failed: " + failCount
dekha "Pass Percentage: " + passPercentage + "%"
Open in Playground
Advanced
06 Bank Account

Example 6: Bank Account System

# Example 6: Bank Account System
# Banking operations with compound assignment

# Global account variable
dhara balance = 1000
dhara accountHolder = "Rama Das"
dhara accountNumber = "ACC123456"

# Function to display account info
karya showAccountInfo()
  dekha ""
  dekha "=== ACCOUNT INFORMATION ==="
  dekha "Account Holder: " + accountHolder
  dekha "Account Number: " + accountNumber
  dekha "Current Balance: Rs. " + balance
  dekha "==========================="
sesa

# Function to deposit money
karya deposit(amount)
  dekha ""
  dekha "--- DEPOSIT ---"
  dekha "Amount to deposit: Rs. " + amount
  
  jadi amount > 0 tahale
    balance += amount
    dekha "Deposit successful!"
    dekha "New Balance: Rs. " + balance
    fera sata
  nahele
    dekha "Error: Invalid amount"
    fera micha
  sesa
sesa

# Function to withdraw money
karya withdraw(amount)
  dekha ""
  dekha "--- WITHDRAWAL ---"
  dekha "Amount to withdraw: Rs. " + amount
  
  jadi amount <= 0 tahale
    dekha "Error: Invalid amount"
    fera micha
  sesa
  
  jadi amount > balance tahale
    dekha "Error: Insufficient balance"
    dekha "Requested: Rs. " + amount
    dekha "Available: Rs. " + balance
    fera micha
  sesa
  
  balance -= amount
  dekha "Withdrawal successful!"
  dekha "New Balance: Rs. " + balance
  fera sata
sesa

# Function to transfer money
karya transfer(amount, recipient)
  dekha ""
  dekha "--- TRANSFER ---"
  dekha "Transferring Rs. " + amount + " to " + recipient
  
  jadi amount <= 0 tahale
    dekha "Error: Invalid amount"
    fera micha
  sesa
  
  jadi amount > balance tahale
    dekha "Error: Insufficient balance"
    fera micha
  sesa
  
  balance -= amount
  dekha "Transfer successful!"
  dekha "Transferred Rs. " + amount + " to " + recipient
  dekha "New Balance: Rs. " + balance
  fera sata
sesa

# Main program - Banking simulation
dekha "================================"
dekha "      WELCOME TO ODIA BANK"
dekha "================================"

# Show initial info
showAccountInfo()

# Test deposits
deposit(500)
deposit(250)

# Test withdrawals
withdraw(300)

# Test insufficient funds
withdraw(5000)

# Test invalid amount
deposit(0)

# Test transfer
transfer(200, "Sita Devi")

# Final balance check
showAccountInfo()

# Transaction history
dekha ""
dekha "=== TRANSACTION SUMMARY ==="
dekha "1. Opening Balance: Rs. 1000"
dekha "2. Deposit: +Rs. 500"
dekha "3. Deposit: +Rs. 250"
dekha "4. Withdrawal: -Rs. 300"
dekha "5. Withdrawal: Rs. 5000 - FAILED"
dekha "6. Deposit: Rs. 0 - FAILED"
dekha "7. Transfer to Sita Devi: -Rs. 200"
dekha "--------------------------------"
dekha "Final Balance: Rs. " + balance
Open in Playground
Advanced
07 Sorting

Sorting Algorithms

# Sorting Algorithms
# Implementations of sorting concepts

# Manual sorting of 3 numbers
karya sort3(a, b, c)
  dekha "Sorting " + a + ", " + b + ", " + c
  
  dhara smallest = a
  dhara middle = b
  dhara largest = c
  
  # Find smallest
  jadi b < smallest tahale
    smallest = b
  sesa
  jadi c < smallest tahale
    smallest = c
  sesa
  
  # Find largest
  jadi b > largest tahale
    largest = b
  sesa
  jadi c > largest tahale
    largest = c
  sesa
  
  # Middle is whatever's left
  middle = a + b + c - smallest - largest
  
  dekha "Sorted: " + smallest + ", " + middle + ", " + largest
sesa

dekha "=== Manual Sorting ==="
sort3(5, 2, 8)
sort3(9, 1, 3)
sort3(7, 7, 4)

# Check if a list is sorted
karya isSorted(a, b, c)
  dhara result = sata
  jadi a > b tahale
    result = micha
  sesa
  jadi b > c tahale
    result = micha
  sesa
  dekha "Is " + a + ", " + b + ", " + c + " sorted? " + result
sesa

dekha ""
dekha "=== Check if Sorted ==="
isSorted(1, 5, 9)
isSorted(3, 7, 2)
isSorted(10, 20, 30)

# Find min and max
karya findMinMax(a, b, c, d)
  dhara minVal = a
  dhara maxVal = a
  
  jadi b < minVal tahale
    minVal = b
  sesa
  jadi c < minVal tahale
    minVal = c
  sesa
  jadi d < minVal tahale
    minVal = d
  sesa
  
  jadi b > maxVal tahale
    maxVal = b
  sesa
  jadi c > maxVal tahale
    maxVal = c
  sesa
  jadi d > maxVal tahale
    maxVal = d
  sesa
  
  dekha "Min: " + minVal + ", Max: " + maxVal
sesa

dekha ""
dekha "=== Min and Max ==="
findMinMax(5, 3, 8, 1)
findMinMax(100, 25, 75, 50)

# Bubble sort visualization (single pass)
karya bubblePass(n1, n2, n3, n4)
  dekha "Before: " + n1 + ", " + n2 + ", " + n3 + ", " + n4
  
  dhara a = n1
  dhara b = n2
  dhara c = n3
  dhara d = n4
  dhara temp = 0
  
  # Pass 1: Compare adjacent and swap
  jadi a > b tahale
    temp = a
    a = b
    b = temp
  sesa
  
  jadi b > c tahale
    temp = b
    b = c
    c = temp
  sesa
  
  jadi c > d tahale
    temp = c
    c = d
    d = temp
  sesa
  
  dekha "After pass: " + a + ", " + b + ", " + c + ", " + d
sesa

dekha ""
dekha "=== Bubble Sort Pass ==="
bubblePass(64, 25, 12, 22)
bubblePass(8, 3, 1, 7)

# Insertion position finder
karya findInsertPosition(value, n1, n2, n3)
  dekha "Inserting " + value + " into [" + n1 + ", " + n2 + ", " + n3 + "]"
  
  dhara position = 4
  
  jadi value <= n1 tahale
    position = 1
  sesa
  
  jadi position == 4 tahale
    jadi value <= n2 tahale
      position = 2
    sesa
  sesa
  
  jadi position == 4 tahale
    jadi value <= n3 tahale
      position = 3
    sesa
  sesa
  
  dekha "Insert at position: " + position
sesa

dekha ""
dekha "=== Insertion Position ==="
findInsertPosition(15, 10, 20, 30)
findInsertPosition(5, 10, 20, 30)
findInsertPosition(25, 10, 20, 30)

# Output:
# === Manual Sorting ===
# Sorting 5, 2, 8
# Sorted: 2, 5, 8
# === Check if Sorted ===
# Is 1, 5, 9 sorted? true
# Is 3, 7, 2 sorted? false
# === Min and Max ===
# Min: 1, Max: 8
# Min: 25, Max: 100
# === Bubble Sort Pass ===
# Before: 64, 25, 12, 22
# After pass: 25, 12, 22, 64
# === Insertion Position ===
# Inserting 15 into [10, 20, 30]
# Insert at position: 2
Open in Playground
Advanced
08 Binary Search

Binary Search

# Binary Search
# Efficient searching in sorted data

# Note: Binary search requires arrays. This example shows
# the algorithm concept with manual comparisons.

# Binary search simulation for 4 numbers
karya binarySearch4(target, n1, n2, n3, n4)
  dekha "Searching for " + target + " in [" + n1 + ", " + n2 + ", " + n3 + ", " + n4 + "]"
  
  dhara found = micha
  dhara position = -1
  
  # Check each position sequentially
  jadi n1 == target tahale
    found = sata
    position = 1
    dekha "Found at position 1!"
  sesa
  
  jadi found == micha tahale
    jadi n2 == target tahale
      found = sata
      position = 2
      dekha "Found at position 2!"
    sesa
  sesa
  
  jadi found == micha tahale
    jadi n3 == target tahale
      found = sata
      position = 3
      dekha "Found at position 3!"
    sesa
  sesa
  
  jadi found == micha tahale
    jadi n4 == target tahale
      found = sata
      position = 4
      dekha "Found at position 4!"
    sesa
  sesa
  
  jadi found == micha tahale
    dekha target + " not found"
  sesa
sesa

dekha "=== Binary Search ==="
binarySearch4(7, 1, 4, 7, 10)
dekha ""
binarySearch4(3, 1, 4, 7, 10)
dekha ""
binarySearch4(10, 1, 4, 7, 10)

# Linear search simulation
karya linearSearch(target, n1, n2, n3, n4, n5)
  dekha "Linear search for " + target
  
  dhara found = micha
  
  jadi n1 == target tahale
    dekha "Found at position 1!"
    found = sata
  sesa
  
  jadi found == micha tahale
    jadi n2 == target tahale
      dekha "Found at position 2!"
      found = sata
    sesa
  sesa
  
  jadi found == micha tahale
    jadi n3 == target tahale
      dekha "Found at position 3!"
      found = sata
    sesa
  sesa
  
  jadi found == micha tahale
    jadi n4 == target tahale
      dekha "Found at position 4!"
      found = sata
    sesa
  sesa
  
  jadi found == micha tahale
    jadi n5 == target tahale
      dekha "Found at position 5!"
      found = sata
    sesa
  sesa
  
  jadi found == micha tahale
    dekha target + " not found"
  sesa
sesa

dekha ""
dekha "=== Linear Search ==="
linearSearch(8, 3, 8, 5, 9, 2)
dekha ""
linearSearch(7, 3, 8, 5, 9, 2)

# Compare search times (simulation)
karya compareSearch(size)
  dekha "Searching in " + size + " elements:"
  dekha "Linear search: ~" + size + " comparisons worst case"
  dhara logSize = 0
  dhara temp = size
  jebe temp > 1
    temp = temp / 2
    logSize = logSize + 1
  sesa
  dekha "Binary search: ~" + logSize + " comparisons worst case"
sesa

dekha ""
dekha "=== Search Efficiency ==="
compareSearch(1000)
dekha ""
compareSearch(1000000)

# Find min and max
karya findMinMax(a, b, c)
  dhara minVal = a
  dhara maxVal = a
  
  jadi b < minVal tahale
    minVal = b
  sesa
  jadi c < minVal tahale
    minVal = c
  sesa
  
  jadi b > maxVal tahale
    maxVal = b
  sesa
  jadi c > maxVal tahale
    maxVal = c
  sesa
  
  dekha "Min: " + minVal + ", Max: " + maxVal
sesa

dekha ""
dekha "=== Min and Max ==="
findMinMax(5, 3, 8)
findMinMax(100, 25, 75)

# Check if sorted
karya isSorted(a, b, c)
  dhara result = sata
  jadi a > b tahale
    result = micha
  sesa
  jadi b > c tahale
    result = micha
  sesa
  dekha "Is " + a + ", " + b + ", " + c + " sorted? " + result
sesa

dekha ""
dekha "=== Check if Sorted ==="
isSorted(1, 5, 9)
isSorted(3, 7, 2)
isSorted(10, 20, 30)

# Output:
# === Binary Search ===
# Searching for 7 in [1, 4, 7, 10]
# Found at position 3!
# === Linear Search ===
# Linear search for 8
# Found at position 2!
Open in Playground