# Sample codes ### 1. Program to Say hello! ```js { name: Main println("Hello, SRON!") } ``` #### OUTPUT: > Hello, SRON! *** ### 2. Program to check if a given number is even or odd. ```js { name: oddEven Int val = inputInt("Enter the value :- ") if: { condition: ${ val % 2 == 0 } println("Even number") } else: { println("Odd number") } } { name : Main oddEven() } ``` #### TERMINAL: > Enter the value :- 17\ > Odd number *** ### 3. Program to use command line arguments. ```js { name: Main args: (List __arglist) println(__arglist) } ``` #### TERMINAL: > sron Namaste SRON 27062003\ > \["Namaste", "SRON", "27062003"] *** ### 4. Program to print integers from 0 to 100,000 using for loop. ```js { name: Main for: { range: (Int i = 0, 100000) OBUFFER += i OBUFFER += '\n' } console : ( OBUFFER , "\n Time Taken= " , getExecTime(), "ms") } ``` #### TERMINAL: > 99996 > \ > 99997 > \ > 99998 > \ > 99999 > > Time Taken= 569ms *** ### 5. Program to find factorial of a given number. ```js { 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 = inputInt("Enter the value :- ") println("\nFactorial of ", val, " = ", factorial(val)) } ``` #### TERMINAL: > Enter the value :- 9 > > Factorial of 9 = 362880 *** ### 6. Program to find if a given number is Armstrong or not. ```js { @ 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 = inputInt("\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.") } } ``` #### TERMINAL: > \==> Enter the value :- 153\ > Yes, 153 is an Armstrong Number. ### 7. Program to detect the name of the operating system. ```js { name: Main windows : { println("Windows OS") } linux : { println("Linux OS") } } ``` #### TERMINAL: > Linux OS *** ### 8. Program to print colorful text on terminal/cli ```js { name: Main println( CLI_COLOR_BRIGHT_BLUE, "Welcome to SRON", CLI_DESIGN_RESET) } ``` #### TERMINAL: > Welcome to SRON *** ### 9. Program to create a simple calculator ```js { name : calculator Double d1, Double d2, Char operator d1 = inputDouble("Number:- ") while : { condition : true operator = inputChar("Operator:- ") d2 = inputDouble("Number:- ") if : { condition : ${ operator == '+' } d1 = ${ d1+d2 } } elif : { condition : ${ operator == '-' } d1 = ${ d1-d2 } } elif : { condition : ${ operator == '*' } d1 = ${ d1*d2 } } elif : { condition : ${ operator == '/' } d1 = ${ d1/d2 } } elif : { condition : ${ operator == '%'} d1 = ${d1 % d2} } else : { println("Invalid Operator Found!") break } println("Answer:- ",d1) } } { name : Main calculator() } ``` #### TERMINAL: > Number:- 27\ > Operator:- \*\ > Number:- 6\ > Answer:- 162.000\ > Operator:- +\ > Number:- 2003\ > Answer:- 2165.000\ > Operator:- -\ > Number:- 5\ > Answer:- 2160.000\ > Operator:- /\ > Number:- 10\ > Answer:- 216.000\ > Operator:- %\ > Number:- 2\ > Answer:- 0.000\ > Operator:- .\ > Number:- 1\ > Invalid Operator Found! ***