-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZamka.cpp
More file actions
49 lines (32 loc) · 792 Bytes
/
Copy pathZamka.cpp
File metadata and controls
49 lines (32 loc) · 792 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
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int main(void){
int l,d,x;
cin >> l >> d >> x;
for(int i=l; i<=d; ++i){ // to find min (N)
int summin = 0;
int valuemin = i;
while(valuemin != 0){
summin += valuemin % 10; // to extract out last digit and add to sum
valuemin /= 10; // divide and repeat if possible
}
if (summin == x){
cout << i ;
break;
}
}
cout << endl;
for(int j=d; j>=l; --j){ // to find max (M)
int summax = 0;
int valuemax = j;
while(valuemax != 0){
summax += valuemax % 10; // to extract out last digit and add to sum
valuemax /= 10; // divide and repeat if possible
}
if (summax == x){
cout << j ;
break;
}
}
return 0;
}