High-precision Division __c language for two integer data in C language

Source: Internet
Author: User

Algorithm:

First, the integer part of the x/y is output, and the remaining number is u=x%y n times to meet the precision requirement.

Each test quotient: x=u*10 for dividend, y for divisor, quotient x/y (integer) as a result of a printout, the remainder is u=x%y. If you are not equal to 0, continue to test the business until u=0 or reach the N-position of the test operator.

Algorithm from: Yangkichang Editor, "computer programming typical examples of fine solutions" high-precision window, national Defense Science and Technology University Press published.

/* High Precision Division of two integer data */
#include <stdio.h>
int main ()
{
long int x,y,u,n;
printf ("Please enter two integers: \ n");
scanf ("%d%d", &x,&y);
printf ("You want to output several decimal points.") (If divisible, you only need to output a decimal point 0) \ n ");
scanf ("%d", &n);
printf ("Result: \ n");
printf ("%d/%d=\n%d.", x,y,x/y);
while (n--)
{
u=x%y;
x=u*10;
printf ("%d", x/y);
if (u==0)
Break
if (n%10==0)
printf ("\ n");
}
printf ("\ n");
return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.