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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:55:40+00:00 2026-05-27T16:55:40+00:00

I need to write a C program that will compare the number of digits

  • 0

I need to write a C program that will compare the number of digits before decimal point and after the decimal point and make sure they are equal.

How can I count how many powers of ten we have before and after the decimal point?

Here is what I have so far:

void main()
{
    is_equal(6757.658);   
}

INT is_equal(double x)
{
   int digits = 0;
   while (x) {
     x /= 10;
     digits++;
   }

   printf("%d ",digits);
}

Is there a better way to do this?

  • 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-27T16:55:41+00:00Added an answer on May 27, 2026 at 4:55 pm

    3rd try:

    Count the number of “digits” before and after a “.”

    • Null is considered not equal to anything

    • I did not test this code it might contain typos.

      int is_equal(char *buffer)
      {
        char *temp;
        int leftLen,rightLen;
      
        temp = strtok(buffer,".");
        if (temp == null) return false;
      
        leftLen = strlen(temp);
      
        temp = strtok(buffer,".");
      
        if (temp == null) return false;
      
        rightLen = strlen(temp);
      
        return (leftLen == rightLen);
      }
      

    Old stuff…

    There are going to be lots of problems here, a floating point (double) in C is not always accurate to 100%; If you perform multiplication or division. If you multiply the digits will change.

    The best way to solve this problem is to render the double to a string and then parse that string.

    You can use sprintf to write the formatted double to a buffer.

    OR

    You can skip using a double all together and use a string to start with.

    Thus building on Marcelo’s answer:

    Read the string from the user into a buffer called buff

    Then parse it with a statement like sscanf(buf, "%d.%d", &a, &b);

    buff is a char * or a char [], a and b are int. You test by saying a == b

    void main()
    {
      is_equal("6757.658");   
    }
    
    int is_equal(char *x)
    {
       int left,right;
    
       sscanf(x, "%d.%d", &left, &right);
    
       printf("Left digits: %d\n\r",left);
       printf("Right digits: %d\n\r",right);
    
       return (left == right);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a C program that will allow me to read/write files
I need to write a program that will take a existing local windows user,
Hey, I need to write a program for OSX that will cause my macbook
I need to write a server program that will open and keep 5 live
I need to write a delegate for a multi-threaded program that will enable/disable a
I need to write a program that will communicate with other .NET programs ...
I need to write a program, that will ask a user to enter a
I need to write program that will be given some path as a parameter,
I need to write a javascript program that will ask the user to enter
I need to write a program in ANSI C that will display the UTF-8

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.