Sample codes

1. Program to Say hello!

{
    name: MAIN
    println("Hello, SRON!")
}

OUTPUT:

Hello, SRON!


2. Program to check if a given number is even or odd.

{
    name: oddEven
    Int val = input_int("Enter the value :- ")
    if: {
        condition: ~{ val % 2 == 0 }~
        println("Even number")
    }
    else: {
        println("Odd number")
    }
}

TERMINAL:

Enter the value :- 17 Odd number


3. Program to use command line arguments.

{
    name: Main
    args: (List __arglist)
    println(__arglist)
}

TERMINAL:

sron 1 2 3 4 5 [1, 2, 3, 4, 5]


4. Program to print integers from 0 to 10,000 using for loop.

{
    name: MAIN
    for: {
        range: (Int i = 0, 10000)
        println(i)
    }
}

TERMINAL:

9997 9998 9999


5. Program to find factorial of a given number.

{
    name: factorial
    args : (Int __val)
    type : Int
    
    Int fac=1
    
    for:{
        range: (Int i = 2,~{ __val+1 }~)
        fac = ~{ fac*i }~
    }
    return : fac

}

{
    name: MAIN
    Int val = input_int("Enter the value :- ")
    println("\nFactorial of ", val, " = ", factorial(val))
}

TERMINAL:

Enter the value :- 5 Factorial of 5 = 120


6. Program to find if a given number is Armstrong or not.

{
    @ This function returns the number of digits in an 'Int' type value

    name : numlen
    args : (Int val)

    @ if the value is 0, then log10() function will return infinity
    if : {

        condition : ~{ val == 0 }~

        return : 1
    }
    elif : {

        condition : ~{ val < 0 }~

        val = ~{ -val }~
    }

    return : floor(~{ log10(val) + 1 }~)
}


{
    name : Armstrong
    args: (Int val)

    Int arm,Int temp,Int len

    len = numlen(copy(val))

    while:{

        condition: ~{ val != 0 }~

        temp = ~{ val%10 }~ 

        arm += ~{ temp^len }~

        val /= 10
    }

    return : arm
}

{
    name : MAIN

    Int val, Int arm

    val = input_int("\n ==> Enter the value :- ")

    arm = Armstrong(copy(val))
    
    if:{

        condition: ~{ val == arm }~

        println("Yes, ", val ," is an Armstrong Number.")

    }

    else:{
        
        println("No, ", val, " is not an Armstrong Number.")

    }

    return : 
}

TERMINAL:

==> Enter the value :- 153 Yes, 153 is an Armstrong Number.

Last updated