Untitled
raw download clone
CPP
views 14
,
size 1149 b
#include <iostream>
#include <math.h>
using namespace std;
void citire (int a[],int &n);
void afisare (int a[],int n);
int prim (int x);
int urmatorul_prim(int n);
void inloc (int a[],int n);
int main ()
{   int n , a[1000];
    citire(a,n);
    inloc(a,n);
    afisare(a,n);
return 0;
}
int urmatorul_prim(int n)
{
    int ok=0 , x;
    x=n+1;
    while (!ok)
        if (prim(x))
            ok =1;
        else
            x++;
    return x;
}
int prim (int x)
{
    int d;
    if(x==0 || x==1)
        return 0;
    else
        if( x==2)
            return 1;
        else
            if( x % 2 == 0)
                return 0;
            else
                for ( d=3 ; d<= sqrt (x); d += 2)
                    if (x % d == 0)
                        return 0;
     return 1;

}
void afisare (int a[],int n)
{
    for (int i=0;i<n;i++)
            cout << a[i] << " ";
}
void citire (int a[],int &n)
{
    cin >> n;
    for (int i=0;i<n;i++)
        cin >> a[i];
}
void inloc (int a[],int n)
{
    for (int i=0;i<n;i++)
        if (!prim(a[i]))
    a[i]=urmatorul_prim(a[i]);
}
close fullscreen
Login or Register to edit or fork this paste. It's free.