Cheatography
https://cheatography.com
STRUCTURA ELEMENTARA A PROGRAMELOR
# include <iostream>
using namespace std;
int main
{ ....
....
} |
CEL MAI MARE DIVIZOR COMUN
while (b!=0)
{ r=a%b;
a=b;
b=r;
}
cout<<"cel mai mare divizor comun dintre"<<a<<"si"<<b<<"este"<<a; |
SUMA CIFRELOR UNUI NUMAR
while (n!=0)
{ u.c=n%10;
s=s+u.c;
n=n/10;
}
cout<<"suma cifrelor numarului"<<n<<"este"<<s; |
Variabila s se declara initial cu 0.
|
|
NUMERE PRIME
for (i=2; i<n/2; i++)
if (n%i==0)
k++;
if (k==0)
cout<<"numarul"<<n<<"este prim"; |
Variabila k se declara initial cu 0.
DIVIZORII UNUI NUMAR
for (i=1; i<n; i++)
if (n%i==0)
cout<<"divizorii numarului"<<n<<"sunt"<<i; |
DESCOMPUNEREA IN FACTORI
while (n!=0)
{ u.c=n%10;
n=n/10;
} |
|
|
MAXIMUL DINTRE DOUA NUMERE
if (a>b)
max=a;
else max=b;
cout<<"maximul dintre"<<a<<"si"<<b<<"este"<<max; |
MINIMUL DINTRE DOUA NUMERE
if (a<b)
min=a;
else min=b;
cout<<"minimul dintre"<<a<<"si"<<b<<"este"<<min; |
NUMERE PARE
if (n%2==0)
cout<<"numarul"<<n<<"este par"; |
NUMERE IMPARE
if (n%2==1)
cout<<"numarul"<<n<<"este impar"; |
PRODUSUL CIFRELOR UNUI NUMAR
while (n!=0)
{ u.c=n%10;
p=p*u.c;
n=n/10;
} |
Variabila p se declara initial cu 1.
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by [deleted]