Jump to content

Recommended Posts

Posted

Salut, vreau sa descompun niste numere (citite din fisier) in factori primi, dar programul calculeaza primele 3 numere si apoi se opreste, ce e gresit ?

COD:

#include <iostream>
#include <fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n,i,V[100],k=2,p;
float dist;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>V[i];
        cout<<V[i]<<endl;
    }
    cout<<endl;

    for(i=1;i<=n;i++)
    {
       while(V[i]!=1)
    {
        p=0;
        while(V[i]%k==0)
        {
            p++;
            V[i]=V[i]/k;
        }
    if(p!=0)
    cout<<k<<" la puterea "<<p<<endl;
    k++;
    }
    }

    f.close();
    g.close();
    return 0;
}

 

Date.in

5
100 97 625 40353607 81

 

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.