- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Print first k digits of 1/n where n is a positive integer in C Program

Input number N such that 1/N will return the output generated as decimal specified till the limit.

It is easy with Floating Point numbers but the challenge is without using them.

**Input **− n=5 k=5**Output **− 20000

It means if n=5 and k=5 than after dividing 1/5 the output should be displayed till 5 decimal points.

## Algorithm

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

## Example

#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; }

## Output

If we run above program then it will generate following output.

first 7 digits of 9 are : 1111111

- Related Questions & Answers
- Sum of the series Kn + ( K(n-1) * (K-1)1 ) + ( K(n-2) * (K-1)2 ) + ... (K-1)n in C++
- Print first m multiples of n in C#
- N’th palindrome of K digits in C++
- Construct Deterministic PDA for a^n b^n where n>=1
- Print numbers with digits 0 and 1 only such that their sum is N in C Program.
- Find all combinations of k-bit numbers with n bits set where 1 <= n <= k in sorted order in C++
- Print n x n spiral matrix using O(1) extra space in C Program.
- Print all increasing sequences of length k from first n natural numbers in C++
- Count total number of digits from 1 to N in C++
- Find smallest number n such that n XOR n+1 equals to given k in C++
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only in C++
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++
- Find gcd(a^n, c) where a, n and c can vary from 1 to 10^9 in C++
- C++ Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++

Advertisements