-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_5.cpp
More file actions
43 lines (29 loc) · 687 Bytes
/
3_5.cpp
File metadata and controls
43 lines (29 loc) · 687 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
#include <iostream>
using namespace std;
int superDigit(long long n) {
if (n < 10)
return n;
long long sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return superDigit(sum);
}
int main() {
string n;
int k;
cout << "Enter number as string: ";
cin >> n;
cout << "Enter value of k: ";
cin >> k;
long long initialSum = 0;
for (char digit : n) {
initialSum += digit - '0';
}
long long total = initialSum * k;
int result = superDigit(total);
cout << "Super digit is: " << result << endl;
cout<<"24ce052_pushti";
return 0;
}