#include <iostream>
#include <time.h>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int find_digital_root(int elem) {
vector<int> temp_vec;
int sum = 0;
while (elem != 0) {
temp_vec.push_back(elem % 10);
elem = elem / 10;
}
if (temp_vec.size() == 1) {
return temp_vec[0];
else {
sum = accumulate(temp_vec.begin(), temp_vec.end(), 0);
temp_vec.clear();
return find_digital_root(sum);
int main()
{
int temp = 0;
for (int i = 100; i <= 200; i++)
temp = find_digital_root(i);
if (temp == 1 || temp == 2 || temp == 3 || temp == 5 || temp == 7) {
cout << i << endl;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <time.h>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int find_digital_root(int elem) {
vector<int> temp_vec;
int sum = 0;
while (elem != 0) {
temp_vec.push_back(elem % 10);
elem = elem / 10;
}
if (temp_vec.size() == 1) {
return temp_vec[0];
}
else {
sum = accumulate(temp_vec.begin(), temp_vec.end(), 0);
temp_vec.clear();
return find_digital_root(sum);
}
}
int main()
{
int temp = 0;
for (int i = 100; i <= 200; i++)
{
temp = find_digital_root(i);
if (temp == 1 || temp == 2 || temp == 3 || temp == 5 || temp == 7) {
cout << i << endl;
}
}
}