r/cpp_questions • u/Star_Gazer_0 • 15h ago
r/cpp_questions • u/dmitryijj • 8h ago
OPEN DEMANDING HELP FOR A BEGGINER
who could possibly explain this program to me as im a begginer into c++:
#include <iostream>
using namespace std;
int main() {
long long n, sum = 0;
if (!(cin>>n)) return 0;
for (int i = 1; i * i <= n; i++) {
if(n%i == 0) {
if(i%2 != 0) {
sum = sum+i;
}
int pair = n/i;
if (pair!=i && pair %2 != 0) {
sum = sum + pair;
}
}
}
cout<<sum;
}
i really tried on doing it myself and went by checking every single divisor method but tried the sqrt method instead to make it faster.i dont really get the last part with pair. Is there anyone who could explain the square rood method of division?
r/cpp_questions • u/Sharp_Alfalfa_1571 • 10h ago
SOLVED Whats the point of functions?
Im new to c++, and I wonder why is there even functions other than the main one, why cant everything be in the main function?