Jump to content

Ajutor Problema Divizori Primi In C++


Recommended Posts

 Calculati suma si produsul divizorilor primi ai unui nr citit.(lucrez in Codeblock)

Nu stiu de ce dar imi da gresit si sper sa poata sa ma ajute cineva.

#include <iostream>

using namespace std;

int main()
    int n, d, s, p;

    cout <<"n=";
    cin >>n;

     if(d%2>0 && d%3>0 && d%5>0 && d%7>0 && n%d==0);

     cout <<"Suma divizori="<<s<<'n'<<"Produs divizori="<<p<<'n';

    return 1;


Respecta si vei fi respectat.

Link to comment
Share on other sites

Nu prea inteleg ce e cu acel if.(ce-i drept , mintea mea nu mai lucreaza la cote bune la ora asta)

O chestie gresita pe care o vad : initializezi suma si produsul in if-ul din for.

Ar fi mai usor daca ai face un subprogram care sa verifice daca un nr este prim , faci un for de la 2 la jumatatea numarului , verifici daca i este nr prim , daca da : s=s+i , p=p*i.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.