Enter a number N such that 1/N will return the output generated in the form specified in decimal until the limit is reached.
It's easy to use floating point numbers, but the challenge is not to use them.
Input− n=5 k=5Output− 20000
This means that if n=5 and k = 5 divided by 1/5 the output should be displayed to 5 decimal places. The Chinese translation of
Start Step 1 -> Declare int variable n to 9 and k to 7 and remain to 1 and i Step 2-> Loop for i to 0 and i<k and i++ Print ((10*remain)/n) Remain = (10*remain)%n Step 3-> end Loop For Stop
#include<stdio.h> int main() { int n = 9, k = 7, remain=1,i ; // taking n for 1/n and k for decimal values printf("first %d digits of %d are : ",k,n); for(i=0;i<k;i++) { printf("%d",((10 * remain) / n)); remain = (10*remain) % n; } return 0; }
If we run the above program, it will The following output is generated.
first 7 digits of 9 are : 1111111
The above is the detailed content of Translate the following into Chinese: Print the first k decimal places of 1/n in a C program, where n is a positive integer. For more information, please follow other related articles on the PHP Chinese website!