Cifrele unui numar

1. Afisare
#include <iostream>

using namespace std;

int main ()
{
    int x,c;
    cout<<"x=";cin>>x;
    while (x!=0)
    {
        c=x%10;
        x=x/10;
        cout<<c<<"\n";
    }
    return 0;
}

2.Palindrom
#include <iostream>

using namespace std;

int main()
{
    int x,y,c,ogl;
    cout<<"x=";cin>>x;
    ogl=0;
    y=x;
    while (x!=0)
    {
        c=x%10;
        x=x/10;
        ogl=ogl*10+c;
    }
    if(ogl==y)cout<<"DA";
    else cout<<"NU";
    return 0;

3.Eliminarea unei cifre
#include <iostream>

using namespace std;

int main()
{
    int a,x,p,c;
    cout<<"a=";cin>>a;
    x=0;
    p=1;
    while(a!=0)
    {
       c=a%10;
       a=a/10;
       if(c%2==0)
       {
          x=x+c*p;
          p=p*10;
       }
    }
    cout<<"x="<<x;
    return 0;
}

4.Verificare munte
#include <iostream>

using namespace std;

int main()
{
    int n,c,x,OK;
    cout<<"n=";cin>>n;
    x=n;
    OK=1;
    while(n>9&&n%10<n/10%10)
       n=n/10;
    if(n==x||n<10) OK=0;
    while(n>9&&n%10>n/10%10)
       n=n/10;
    if(n>9) OK=0;
    if(OK==1) cout<<"DA";
    else cout<<"NU";
    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s