0% found this document useful (0 votes)
43 views3 pages

Calculati Cmmdc-Ul Nr. Naturale A Si B

The document contains algorithms for solving several mathematical problems written in C++ code. The problems include calculating the greatest common divisor and least common multiple of two numbers, summing and multiplying the digits of a number, counting the digits of a number, finding the sum and product of the divisors of a number, determining if a number is perfect or prime, reversing a number, checking if a number is a palindrome, and decomposing a number into prime factors. The algorithms use loops and conditionals to iterate through the numbers and check properties.

Uploaded by

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

Calculati Cmmdc-Ul Nr. Naturale A Si B

The document contains algorithms for solving several mathematical problems written in C++ code. The problems include calculating the greatest common divisor and least common multiple of two numbers, summing and multiplying the digits of a number, counting the digits of a number, finding the sum and product of the divisors of a number, determining if a number is perfect or prime, reversing a number, checking if a number is a palindrome, and decomposing a number into prime factors. The algorithms use loops and conditionals to iterate through the numbers and check properties.

Uploaded by

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

natural a,b Calculati cmmdc-ul nr. naturale a si b.

citeste a, b #include<iostream>
cat timp a  b executa using namespace std;
int main(){
daca a>b atunci unsigned int a,b;
aa-b cin>>a>>b;
altfel while(a!=b)
bb-a if(a>b) a=a-b;
else b=b-a;
cout<<"cmmdc= "<<a;
scrie “ cmmdc =“, a
return 0;}
natural a,b,p Calculati cmmmc-ul nr. naturale a si b.
citeste a, b #include<iostream>
using namespace std;
p←a*b
int main(){
cat timp a  b executa unsigned int a,b,p;
daca a>b atunci cin>>a>>b; p=a*b;
aa-b while(a!=b)
altfel if(a>b) a=a-b;
bb-a else b=b-a;
cout<<"cmmmc= "<<p/a;
scrie “ cmmmc =“, p/ a
return 0;}
natural x,s Calculati suma cifrelor numarului xєN.
s←0 #include<iostream>
using namespace std;
citeste x
int main(){
cat timp x  0 executa unsigned int x, s=0;
s←s+x % 10 cin>>x;
x←[x /10] while(x!=0){s=s+x%10;
▀ x=x/10;}
scrie s cout<<"suma= "<<s;
return 0;}
natural x, p Calculati produsul cifrelor numarului xєN.
p←1 #include<iostream>
using namespace std;
citeste x
int main(){
cat timp x  0 executa unsigned int x, p=1;
p←p*(x % 10) cin>>x;
x←[x /10] while(x!=0){
▀ p=p*(x%10);
scrie p x=x/10;}
cout<<"produs= "<<p;
return 0;}
natural x, k Numarati cifrele numarului natural x.
k←0 #include<iostream>
using namespace std;
citeste x
int main(){unsigned int x, k=0;
cat timp x  0 executa cin>>x;
k←k+1 while(x!=0){k++;
x←[x /10] x=x/10;}
▀ cout<<"nr_cifre= "<<k;
scrie k return 0;}
intreg x,d,s Suma divizorilor numarului x
citeste x include<iostream>
using namespace std;
s←0
int main(){
pentru d1,x executa unsigned int d,x,s=0;
daca x mod d=0 atunci cin>>x;
s s+d for(d=1; d<=x;d++)
if (x%d==0) s=s+d;
scrie s cout<<s;
return 0;}
intreg x,d,s Verificati daca x e perfect(6=1+2+3)
citeste x #include<iostream>
using namespace std;
s←0
int main(){
pentru d1,[x/2] executa unsigned int d,x,s=0;
daca x mod d=0 atunci cin>>x;
s s+d for(d=1; d<=x/2; d++)
if (x%d==0)
daca s=x atunci s=s+d;
if(s==x) cout<<"perfect";
scrie "perfect"
else cout<<"nu";
altfel scrie "nu" return 0;}

intreg x,d,p Produsul divizorilor numarului x


citeste x #include<iostream>
using namespace std;
p←1
int main(){
pentru d1, x executa unsigned int i,x,p=1;
daca x mod d=0 atunci cin>>x;
p p*d for(i=1; i<=x; i++)
if (x%i==0) p=p*i;
scrie p cout<<p;
return 0;}
intreg x,d,k Numarul divizorilor numarului x //divizori propri
citeste x #include<iostream>
using namespace std;
k←0
int main(){
pentru d1, x executa unsigned int i,x,k=0;
daca x mod d=0 atunci cin>>x;
k k+1 for(i=1; i<=x; i++) // for(i=2; i<=x/2; i++)
if (x%i==0) k++;
scrie k cout<<k;.
return 0;}
natural x,inv Calculati "oglinditul"numarului nєN.
inv←0 ex. x =123 inv=321
citeste x
#include<iostream>
cat timp x  0 executa using namespace std;
inv←inv*10+x % 10 int main(){
x←[x /10] unsigned int x, inv=0;
▀ cin>>x;
scrie inv while(x!=0){
inv=inv*10+x%10;
x=x/10;}
cout<<"oglindit= "<<inv;
return 0;}
natural x,n,inv verificati daca n e palindrom
inv←0 ex. x =121 inv=121
#include<iostream>
citeste n
using namespace std;
x←n int main(){
cat timp x  0 executa unsigned int x,cx, inv=0;
inv←inv*10+x % 10 cin>>x;
x←[x / 10] cx=x;
▀ while(cx!=0){
daca n=inv atunci inv=inv*10+cx%10;
cx=cx/10;}
scrie” palindrom” if (x==inv) cout<<"palindrom";
altfel scrie” nu palindrom” else cout<<"nu";
▀ return 0;}
intreg x,d,prim Verificati daca x este prim.
citeste x #include<iostream>
using namespace std;
prim←1
int main(){
daca x<2 atunci unsigned int i,x,prim=1;
prim←0 cin>>x;
pentru d2, [x /2] && prim=1 executa if (x<2)
daca x mod d=0 atunci prim=0;
prim0 for(i=2; i<=x/2 && prim==1; i++)
if (x%i==0)
prim=0;
daca prim=1 atunci if prim==1) cout<<x<<”este prim”;
scrie "prim" else cout<<x<<”nu este prim”;
altfel scrie "nu" }

natural x,p,d Descompuneti numarul x in factori primi


d←2
#include<iostream>
citeste x
using namespace std;
cat timp x  1 executa unsigned int main(){
p←0 int x, p,d=2;
cat timp x %d=0 executa cin>>x;
p←p+1 while(x!=1){p=0;
x←[x / d] while(x%d==0){p++;
▀ x=x/d;}
if(p>0)
daca p>0 atunci
cout<<d<<"la puterea"<<p<<endl;
scrie d,” la puterea”,p d++;}
▀ return 0;}
d←d+1

You might also like