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

  • Home
  • SEARCH
  • 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 8782627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:36:52+00:00 2026-06-13T20:36:52+00:00

I have an assignment that requires me to first set up integer arrays to

  • 0

I have an assignment that requires me to first set up integer arrays to store arbitrarily large numbers. By using each element of an int array, I can hold one digit per element because int variable types are 32 bits and can only reach up to about 2 billion before failing. I know that there are other libraries using BigInt but I wanted to make my own arrays instead.

I tested my code out, but it doesn’t seem to be accepting values past 9 digits until it starts to fail.

int * toArray(int, int);
int main()
{
    int n, *res, counter, i;
    printf("Input: ");
    scanf("%d", &n);
    while(n>0){
         n/=10;
         counter++;
    }
    res = toArray(n, counter);
    for(i=1;i<=counter;i++){
         printf("%d", *(res)+i);
    }
    printf("\n");
}   

int * toArray(int n, int counter)
{
    int i;
    int *numberArray = malloc(sizeof(int) * counter);
    for(i=0; i< counter; i++)
    {   
         numberArray[i] = n % 10;
    }
    return numberArray;
}

I want to be able to accept close to twenty digits at the very least. I know this can be done with int arrays, although char arrays (or strings) are also a possibility. But I wanted to use int arrays instead. Any help in understanding why it fails around 9 digits and suggestions for going past that would be very much appreciated. Thank you.

  • 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-13T20:36:53+00:00Added an answer on June 13, 2026 at 8:36 pm

    The problem is that you are reading an int from keyboard

    scanf("%d", &n);
    

    so therefore no matter how many digits you enter, you still will only get 9 digits.

    In order to be able to enter an arbitrary number you would have to read it as a string instead, then convert it to your int array.

    EDIT:

    this way (for instance) would allow for 20 digits

      char ch;
      int digits[20];
      int i = 0;
      do
      {
        ch = fgetc(stdin);
        if ( isdigit(ch) )
        {
          digits[i++] = ch - 48; // convert ASCII to int
        }
      }
      while (isdigit(ch) && i < sizeof(digits)/sizeof(digits[0]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My assignment requires that I have an ER diagram that shows the dependencies between
I have quite a large XSL document for an assignment that does a number
I have an assignment that requires us to implement a doubly linked list class.
I have this assignment due that requires the usage of FLTK. The code is
Basically, I have an assignment that requires me to find the mode of a
So I have an assignment for school that requires me to create a fixed
I am a student in college and have an assignment which requires finding large
I have an assignment that requires exposing a web service to 3rd party vendor
I'm having a bit of trouble. I have an assignment that requires me to
I have an assignment that wants me to write an ternary search algorithm and

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.