r/cpp_questions • • 15h ago

OPEN Learn C++ on learncpp.com but the chapter exercices aren't enough and I' very weak at coding. Is there another resource made specifically to give me exercices to solve

33 Upvotes

r/cpp_questions • • 8h ago

OPEN DEMANDING HELP FOR A BEGGINER

1 Upvotes

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 • • 10h ago

SOLVED Whats the point of functions?

0 Upvotes

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?