Print table in SML-NJ


Print Table in SML 

Following is the code snippet for printing table in sml.

(*Table printing program in SML-NJ *)
(* To under stand the looping concept in SML-NJ*)
(* In function table 3 values are passed
1. Start
2. Number table to be printed
3. Maximum (Upto where table to be printed)
*)

fun table (n,num,max) =
  if n > max then
    print "\n"
  else (
    print (Int.toString (num) ^ " * " ^Int.toString (n) ^" = "^Int.toString (n*num) ^"\n");
    table (n + 1,num,max)
  );
table (1,2,10);(*table(initilization , table to be printed , Upto the limit)*)


Output:

Screenshot of Table Printing code (Above Code)

Comments

Popular posts from this blog

Conditional Statement in SML (if else in SML)

Getting Started with SML