Ergänzung der Programme

This commit is contained in:
Leaced 2017-04-02 16:42:35 +02:00
parent cb0b4e7ee5
commit 41148de89c
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,36 @@
#include<iostream>
#include<string>
#include<sstream>
int main()
{
std::string input;
unsigned long long max;
std::cout << "Geben sie an bis zu welcher Zahl nach befreundeten Zahlen gesucht werden soll: ";
getline(std::cin, input);
std::stringstream(input) >> max;
if(max<284)
{
std::cout << "\nEs wurden keine befreundeten Zahlen gefunden.";
getchar();
return(0);
}
std::cout << "\nbefreundete Zahlen sind:\n";
for(unsigned long long number = 284; number<=max; number++)
{
unsigned long long sum = 0, sum2 = 0;
for(unsigned long long factor = 1; factor*2<=number; factor++) if(number%factor==0) sum += factor;
if(sum<number && sum>=220) for(unsigned long long factor = 1; factor*2<=sum; factor++) if(sum%factor==0) sum2 += factor;
if(sum2==number) std::cout << sum << " und " << sum2 << "\n";
}
getchar();
return(0);
}