forked from sourav-122/hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
38 lines (32 loc) · 670 Bytes
/
string.cpp
File metadata and controls
38 lines (32 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// CPP program to find smallest
// number to find smallest number
// with N as sum of digits and
// divisible by 10^N.
#include <bits/stdc++.h>
using namespace std;
void digitsNum(int N)
{
// If N = 0 the string will be 0
if (N == 0)
cout << "0\n";
// If n is not perfectly divisible
// by 9 output the remainder
if (N % 9 != 0)
cout << (N % 9);
// Print 9 N/9 times
for (int i = 1; i <= (N / 9); ++i)
cout << "9";
// Append N zero's to the number so
// as to make it divisible by 10^N
for (int i = 1; i <= N; ++i)
cout << "0";
cout << "\n";
}
// Driver Code
int main()
{
int N = 5;
cout << "The number is : ";
digitsNum(N);
return 0;
}