Untitled
raw download clone
TEXT
views 24
,
size 859 b
#include<iostream>
using namespace std;

void citire(int &n , int v[101])
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
}

void afisare(int n, int v[101])
{
    for(int i=1;i<=n;i++)
        cout<<v[i]<<" ";
}

int prim(int n)
{
    if(n<=1)
        return 0;
    else
        if(n!=2&&n%2==0)
            return 0;
        else
            for(int d=3;d*d<=n;d+=2)
                if(n%d==0)
                    return 0;
    return 1;

}
int urmatorul_prim(int n)
{
    int i=n+1;
    while(!prim(i))
        i++;
    return i;

}

void inlocuire(int n, int v[1001])
{
    int i;
    for(i=1;i<=n;i++)
    {
        if(prim(v[i])==0)
            v[i]=urmatorul_prim(v[i]);
    }
}

int main()
{
    int n,v[1001];
    citire(n,v);
    inlocuire(n,v);
    afisare(n,v);

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.