0% found this document useful (0 votes)
16 views6 pages

Algoritmi

Uploaded by

Andrei SDU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Algoritmi

Uploaded by

Andrei SDU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

// Suma cifrelor lui n

#include<iostream.h>
int n,s,c;
void main()
{
cout<<„n=”;
cin>>n;
while(n!=0)
{
c=n%10; // extrag ultima cifra
s=s+c;
n=n/10; // tai ultima cifra
}

cout<<„Suma cifrelor=”<<s;
}

// Numarul de cifre ale lui n

#include<iostream.h>
int n, nr;
void main()
{
cout<<„n=”;
cin>>n;
while(n!=0)
{
nr=nr+1;
n=n/10; // tai cifrele
}
cout<<„Nr. de cifre=”<<nr;
}
// Inversul lui n

#include<iostream.h>
int n, inv,c;
void main()
{
cout<<„n=”;
cin>>n;
inv=0;
while(n!=0)
{
c=n%10;
inv=inv*10+c;
n=n/10;
}
cout<<„Inversul=”<<inv;
}
// Palindrom

#include<iostream.h>
int n,inv, c, copie;
void main()
{
cout<<„n=”;
cin>>n;
copie=n;
while(n!=0)
{
c=n%10;
inv=inv*10+c;
n=n/10;
}
if(copie==inv)
cout<<„Palindrom”;
else
cout<<„Nu”;
}
// Numarul PRIM
#include<iostream.h>
int n, ok, d;
void main()
{
cin>>n;
d=2; ok=1;
while(d<=n/2&&ok==1)
if(n%d==0)
ok=0;
else
d++;
if(ok==1)
cout<<„Prim”;
else cout<<„Nu”;
// Descompunerea in factori primi

#include<iostream.h>
void main()
{
int a,d,p;
cout<<„=a”;
cin>>a;
d=2;
while(a>1)
{
p=0;
while(a%d==0)
{
p=p+1;
a=a/d;
}
if(p) // <=> if(p!=0)
cout<<d<<„^”<<p<<” „;
d++;
}
}
// Multimea divizorilor proprii ai lui n, adica in afara de 1 si n

#include<iostream.h>
int n,d;
void main()
{
cin>>n;
d=2;
while(d<=n/2)
{
if(n%d==0)
cout<<d<<” „; // afisez divizorii proprii ai lui n, care se pot gasi in
[2,n/2]
d++;
}
}
// CMMDC a 2 nr a si b
#include<iostream.h>
int a,b;
void main()
{
cin>>a>>b;
while(a!=b)
if(a>b)
a=a-b;
else
b=b-a;
cout<<„CMMDC=”<<a;
}
// CMMMC
#include<iostream.h>
int a,b,x,y;
void main()
{
cin>>x>>y;
a=x; b=y;
while(x!=y)
if(x>y)
x=x-y;
else y=y-x;
cout<<„CMMC=”<<(a*b)/x;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy