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 6979827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:08+00:00 2026-05-27T17:56:08+00:00

I am trying to create a function that will take an int and separately

  • 0

I am trying to create a function that will take an int and separately return the leftmost digit and the rest of the number.

int idigitizer(int *number) {
int i = 1;
int head = 0;
int tmp = 0;

tmp = *number;
while (tmp > 9) {
    if ((tmp/i) < 10) {
        head = tmp/i;
        *number = *number - (head*i);
        return head;
    } else {
        i = i*10;
    }
}
number = 0;
return tmp;
} 

idigitizer returns the leftmost part of the number and *number will carry the rest.
I will have a loop in my main that will keep calling idigitizer until all the digits of the number get separated.
The thing is I don’t know how to handle zeroes and how to make this process terminate correctly when it is done with the last digit. Any help is welcome. Thanks in advance.

EDIT : To make it clearer. I don’t want the possible zeroes in the middle of a number to get lost. If i get the number 100047 as input I want idigitizer to return:

return - *number
         100047
1        00047
0        0047
0        047
0        47
4        7
7
  • 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-05-27T17:56:09+00:00Added an answer on May 27, 2026 at 5:56 pm

    I would use something like this instead:

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int getFirstDigit( int number );
    int getRestOfNumber( int number );
    int getNumberOfMissingZeros (int number, int restOfNumber);
    
    int main(int argc, char* argv[]){
    
       int x = 500574;
       int firstDigit;
       int restOfNumber;
    
       int n; /* loop index */
    
       firstDigit = getFirstDigit(x);
       restOfNumber = getRestOfNumber(x);
    
       printf("The first digit of %d is %d.\n",x,firstDigit);
       printf("The rest of the number is ");
    
       for( n = 0; n<getNumberOfMissingZeros(x,restOfNumber); ++n ){
         printf("0");
       }
    
       printf("%d.",restOfNumber);
    
       return EXIT_SUCCESS;
      }
    
    int getFirstDigit( int number ){
    
      return number / (int)floor( pow(10,floor(log10( (double)number ))) );
    
    }
    
    int getRestOfNumber( int number){
    
       return number % (int)floor( pow(10,floor(log10( (double)number ))) );
    
    }
    
    int getNumberOfMissingZeros (int number, int restOfNumber){
    
      int digitsOriginally;
      int digitsInRestOfNumber;
    
      digitsOriginally = floor(log10( (double)number ) );
      digitsInRestOfNumber = floor(log10( (double)restOfNumber ) );
    
      return digitsOriginally - digitsInRestOfNumber - 1;
    
    }
    

    The magic is in the expression (int)floor( pow(10,floor(log10( (double)number ))) ); This gets the size of the value, like for 52330, it would return 10000, since there are five digits in 52330. This makes it easy to extract the highest digit.

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

Sidebar

Related Questions

I'm trying to create a function that will take a string which could be
I am trying to create a jQuery function that will take a string and
I'm trying to create a simple program or function that will take the users
I'm trying to create a function so that =processCells(A1:A10) will take the range of
I'm trying to create a function in Objective-C that will take __FILE__ and _cmd
I am trying to create a function that will block access to some of
I am new to Prolog and I'm trying to to create function that will
I am trying to create an OCaml function rv that will go through a
Update I'm trying to create a simple Go function which will simply take in
I'm trying to create a function that will store and repeat another function given

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.