Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:29:43+00:00 2026-06-17T06:29:43+00:00

I am writing an ocaml program and I can’t figure out how to look

  • 0

I am writing an ocaml program and I can’t figure out how to look at specific digits of an int

so say for example we have

let a = 405;;

I want to be able to look at the first digit, 4, or the second one, 0. How can I accomplish this? I was thinking of turning it into a string and looking at the chars, but I feel like there should be another way of doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:29:44+00:00Added an answer on June 17, 2026 at 6:29 am

    You can write a recursive function to extract all digits from a number:

    (* Assuming n is a non-negative number *)
    let digits n =
        let rec loop n acc =
            if n = 0 then acc
            else loop (n/10) (n mod 10::acc) in
        match n with
        | 0 -> [0]
        | _ -> loop n []
    

    Once you have a list of digits

    # digits 405;;
    - : int list = [4; 0; 5]
    

    you can get any digit by using some List functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing some XML documentation for a predicate helper class. But I can't figure out
I'm writing a simple little ocaml program that reads an algebraic statement in from
I'm writing a program in ocaml using ocamlgraph and wondering if I am to
I'm writing a program in ocaml containing some loops for, my problem is that
Writing a file utility to strip out all non-ASCII characters from files. I have
I am writing a lexer in OCaml for a small language, I have a
I am writing a ocaml project, in which I have a function that replace
Writing a program for class, restricted to only scanf method. Program receives can receive
I'm writing a recursive function in Ocaml that's supposed to count the number of
I am experimenting with writing a toy compiler in ocaml. Currently, I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.