Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include<math.h>
- using namespace std;
- bool premier(int x)
- {
- bool v(true);
- int i(2);
- if (x==2)
- {
- v=true;
- }
- else if (x==1)
- {
- v=false;
- }
- else{
- for(i=2;i<x-1;++i)
- {
- if (x%i==0)
- {
- v=false;
- }
- }
- }
- return v;
- }
- void saisie(int &n,vector<int>&(tab))
- {
- do
- {
- cout<<"n=";
- cin>>n;
- }
- while
- (n<3||n>10);
- int z(0);
- int i(0);
- for(i=0;i<n;++i)
- {
- do
- {
- cout<<"tab["<<i<<"]=";
- cin>>z;
- }
- while(z<10||z>=1000);
- tab.push_back(z);
- }
- }
- bool riche(int z)
- {
- int i(1);
- bool v(false);
- do
- {
- i=i+1;
- if (z%(i*i)==0)
- {
- v=true;
- }
- }
- while((v==false)&&(i*i)<z);
- return v;
- }
- void decomposition(int z)
- {
- int i(2),r(0);
- cout<<z<<"=";
- do
- {
- if (premier(i)&&z%i==0)
- {
- cout<<i<<"*";
- z=z/i;
- r=i;
- }
- else
- {
- i=i+1;
- }
- }
- while (premier(z)==false);
- cout<<z;
- cout<<endl;
- }
- void aff(int n,vector<int>(tab))
- {
- int i(0);
- cout<<"les nombres riches sont:"<<endl;
- for(i=0;i<n-1;++i)
- {
- if (riche(tab[i]))
- {
- cout<<tab[i]<<",";
- }
- }
- if (riche(tab[n-1]))
- {
- cout<<tab[n-1];
- }
- cout<<"en effet"<<endl;
- for (i=0;i<n-1;++i)
- {
- if (riche(tab[i]))
- {
- decomposition(tab[i]);
- }
- }
- }
- int main()
- {
- int n(0);
- vector<int>tab;
- saisie(n,tab);
- aff(n,tab);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement