Show Menu
Cheatography

C++ algoritmi Cheat Sheet by [deleted]

STRUCTURA ELEMENTARA A PROGRA­MELOR

# include <io­str­eam>
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­<<"s­i"<<­b<<­"­est­e"<<a;

SUMA CIFRELOR UNUI NUMAR

while (n!=0)
{ u.c=n%10;
s=s+u.c;
n=n/10;
}
cout<<­"suma cifrelor numaru­lui­"­<<n­<<"e­ste­"­<<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<<­"­num­aru­l"<<­n<<­"este prim";
Variabila k se declara initial cu 0.

DIVIZORII UNUI NUMAR

for (i=1; i<n; i++)
if (n%i==0)
cout<<­"­div­izorii numaru­lui­"­<<n­<<"s­unt­"­<<i;

DESCOM­PUNEREA 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­<<"s­i"<<­b<<­"­est­e"<<max;

MINIMUL DINTRE DOUA NUMERE

if (a<b)
min=a;
else min=b;
cout<<­"­minimul dintre­"­<<a­<<"s­i"<<­b<<­"­est­e"<<min;

NUMERE PARE

if (n%2==0)
cout<<­"­num­aru­l"<<­n<<­"este par";

NUMERE IMPARE

if (n%2==1)
cout<<­"­num­aru­l"<<­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.
       

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Numeric Formats Cheat Sheet

          More Cheat Sheets by [deleted]