Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Functie care returneaza suma cifrelor pare ale lui x. x-parametru
- int sumapare(int x)
- {
- int s=0;
- while (x)
- {
- if (x%2==0)
- s=s+s%10;
- x/=10;
- }
- return s;
- }
- 2. Functie care verifica daca numarul transmis ca parametru are toate cifrele impare.
- int cifimpare (int x)
- {
- while (x)
- {
- if ((x%10)%2==0)
- return 0;
- x=x/10;
- }
- return 1;
- }
- 3. Funcite care verifica daca nr transmis ca parametru are cel putin o cifra para.
- int par(int x)
- {
- while (x)
- {
- if((x%10)%2==0)
- return 1;
- x=x/10;
- }
- return 0;
- }
- 4. Functie care verifica daca un nr transmis ca parametru are cifrele distincte doua cate doua.
- int distincte(int x)
- {
- int fv[10]={0},i,cif
- while (x)
- {
- cif=cif%10;
- fv[cif]++;
- if (fv[cif]>1)
- return 0;
- x=x/10;
- }
- return 1;
- }
- 5. O functie care primeste ca parametru un nr de max 9 cifre, intreg, si returneaza numarul obtinut prin permutarea cifrelor
- sale cu o pozitie.
- varianta 1
- int permutari_stanga(int x)
- {
- int x,p,nr=0,xx
- xx=x;
- while (xx)
- {
- nr++;
- x=x/10;
- }
- p=pow(10,nr-1);
- x=x/p+(x%p)*10;
- return x;
- }
- varianta 2
- /* functiw care permuta spre dr. cifrele unui vector cu o pozitie */
- void vector(int v[10],int k)
- {
- int aux,i;
- aux=v[k];
- for (i=k-1;i>=1;i--)
- v[i+1]=v[i];
- v[1]=aux;
- }
- /* inversez cifrele in vecotr */
- void inversez(int v[10],int &k, int x)
- {
- int cif;
- k=0;
- while (x)
- {
- cif=x/10;
- k++;
- v[k]=cif;
- x=x/10;
- }
- }
- /* formez numarul */
- int rezolvare (int x)
- {
- int v[10],k,ogl=0,i;
- rezolvare (v,k,x);
- vector (v,k);
- for (i=k;i>=1;i--)
- ogl=ogl*10+v[i];
- return ogl;
- }
- 6. Se citeste un nr de max 9 cifre. /* functiw care permuta spre dr. cifrele unui vector cu o pozitie */
- void vector(int v[10],int k)
- {
- int aux,i;
- aux=v[k];
- for (i=k-1;i>=1;i--)
- v[i+1]=v[i];
- v[1]=aux;
- }
- /* inversez cifrele in vecotr */
- void inversez(int v[10],int &k, int x)
- {
- int cif;
- k=0;
- while (x)
- {
- cif=x/10;
- k++;
- v[k]=cif;
- x=x/10;
- }
- }
- /* formez numarul */
- int rezolvare (int x)
- {
- int v[10],k,ogl=0,i;
- rezolvare (v,k,x);
- vector (v,k);
- for (i=k;i>=1;i--)
- ogl=ogl*10+v[i];
- return ogl;
- 7. Verificat daca e super prim. Un nr se numeste prim daca atat el, cat si toate permutarile sunt nr prime. Ex: 133 313 331
- #include <iostream>
- #include <cmath>
- #include <fstream>
- using namespace std;
- int nrcifre(int x)
- {
- int nr=0;
- while (x)
- {
- x=x/10;
- nr++;
- }
- return nr;
- }
- int nrprim (int x)
- {
- int i;
- if (x==0 || x==1 || (x%2==0 && x!=0))
- return 0;
- for (i=3;i<=sqrt(x);i=i+2)
- if (x%i==0)
- return 0;
- return 1;
- }
- int rotire (int x,int nr)
- {
- int p;
- p=pow(10,nr-1);
- x=x/p+(x%p)*10;
- return x;
- }
- int extraprim(int x)
- {
- int k=nrcifre(x),i;
- for (i=1;i<=k;i++)
- {
- if (nrprim(x)==0)
- return 0;
- }
- x=rotire(x,k);
- return 1;
- }
- int main()
- {
- int x;
- cout<<"x= ";
- cin>>x;
- if (extraprim(x)==1)
- cout<<"DA";
- else
- cout<<"NU";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement