mercredi 1 juillet 2020

Why is program not executing properly?

I just wrote a simple prime factors finding program but when I'm trying to run it, it compiles and partially executes!

Logic used is this: https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/ Here's the code:

#include <iostream>
#include "cmath"
using namespace std;

int main()
{
    int a,i;
    printf("Enter the number:");
    scanf("\n%d",&a);
    printf("Its factors are:");
    while(a%2==0) {
        a = a/2;
        printf("2");
    }
    for (i=3;i=< sqrt(a);i+=2)
        if (a%i == 0) {
            cout<<i;
            a = a/i;
        }
        else {
            cout<<a;
        }
    return 0;
}

After running, it displays the line "Enter the number:" but after giving

Edit: I changed the code as per the suggestions. But this new one is also not working. It's not giving any error just not giving the required output.

Aucun commentaire:

Enregistrer un commentaire