Program in c which finds powerful numbers

Solved/Closed
Fatu - Nov 9, 2009 at 02:49 PM
 Assaad - Nov 16, 2009 at 03:43 PM
Hello,i need to write a program in c which can find all the powerful numbes up to 1000...plz help me..it must be ready by thursday...thank you...

1 response

xpcman Posts 19528 Registration date Wednesday October 8, 2008 Status Contributor Last seen June 15, 2019 1,824
Nov 9, 2009 at 03:49 PM
Do you mean Prime Numbers? I have no idea what a powerful number is.
2
i will answer you with a link..thanks for your interest:
https://en.wikipedia.org/wiki/Powerful_number
0
I will answer you with a link..thanks for your interest:
https://en.wikipedia.org/wiki/Powerful_number
0
Assaad > Fatu
Nov 16, 2009 at 03:43 PM
#include <iostream>
using namespace std;

int main() {
    int endRange = 500, var1, var2, var3, finalVar;
    for (int counter = 4; counter < endRange = 500; counter++) {
        var1 = counter;
        var2 = 3;
        var3 = 0;
        finalVar = var1;
        while (var1 % 2 == 0) {
            var1 /= 2;
            var3 += 1;
        }

        while ((var2 <= var1) && (var3 != 1)) {
            var3 = 0;
            while (var1 % var2 == 0) {
                var1 /= var2;
                var3 += 1;
            }
            var2 += 2;
        }

        if (var3 > 1)
            cout << finalVar << ' ';
    }
}
0