Program in c which finds powerful numbers [Solved/Closed]

Fatu - Nov 9, 2009 at 02:49 PM - Latest reply:  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...
See more 

4 replies

Best answer
xpcman 19319 Posts Wednesday October 8, 2008Registration dateModeratorStatus September 22, 2018 Last seen - Nov 9, 2009 at 03:49 PM
2
Thank you
Do you mean Prime Numbers? I have no idea what a powerful number is.

Thank you, xpcman 2

Something to say? Add comment

CCM has helped 1871 users this month

i will answer you with a link..thanks for your interest:
http://en.wikipedia.org/wiki/Powerful_number
I will answer you with a link..thanks for your interest:
http://en.wikipedia.org/wiki/Powerful_number
#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 << ' ';
    }
}