Jump to content

Recommended Posts

  • Moderators
Posted

1.

#include <fstream>
using namespace std;

ifstream in("fractii.in");
ofstream out("fractii.out");

int main()
{
    int n;
    in >> n;
    for ( int i = 1 ; i <= n ; i++ )
    {
        int x, y, aux_x, aux_y, c;
        in >> x >> y;
        aux_x = x;
        aux_y = y;
        
        /**
         * Algoritmul lui Euclid pentru determinarea cmmdc
         */
        while ( aux_y )
        {
            c = aux_x % aux_y;
            aux_x = aux_y;
            aux_y = c;
        }

        out << x / aux_x << '/' << y / aux_x << 'n';
    }
    return 0;
}

2.

#include <iostream>

using namespace std;

int main()
{
    int t, d = 2, s = 0;
    cin >> t;
    while ( t > 1 )
    {
        while ( t % d == 0 )
        {
            t /= d;
            s++;
        }
        d++;
    }
    cout << s;
    return 0;
}

3.

#include <fstream>
#include <vector>

using namespace std;

ifstream in("palindrom.in");
ofstream out("palindrom.out");

int main()
{
    vector < int > elemente_palindrom;
    int n, i, x;
    
    in >> n;
    
    for( i = 1 ; i <= n ; i++ )
    {
        in >> x;
        out << x << ' ';
        
        int aux = 0, copie = x;
        
        while ( copie )
        {
            aux = aux * 10 + copie % 10;
            copie /= 10;
        }
        
        if ( aux == x )
        {
            elemente_palindrom.push_back ( x );
        }
        
    }
    out << endl;

    for ( i = 0 ; i < elemente_palindrom.size() ; i++ )
    {
        out << elemente_palindrom.at( i ) << ' ';
    }
    
    out << endl << "Mesaj palindrom";
    
    return 0;
}

5.

#include <fstream>
using namespace std;
ifstream in("numere.in");
ofstream out("numere.out");

int main()
{
    int n, i, x;
    in >> n;
    for (i=1 ; i <= n ; i++)
    {
        in >> x;
        out << x << endl;
    }
    return 0;
}

6.

#include <fstream>

using namespace std;

ifstream in("nr.in");
ofstream out("nr.out");

int main()
{
    int nr_elem, numar, p, numar_nou;
    
    in >> nr_elem;
    
    for (int i = 1 ; i <= nr_elem ; i++)
    {
        in >> numar;
        p = 1;
        numar_nou = 0;
        
        while ( numar )
        {
            if ( numar % 10 )
            {
                numar_nou += p * ( numar % 10 );
                p *= 10;
            }
            
            numar /= 10;
        }
        
        out << numar_nou << ' ';

    }
    
    return 0;
}

7.

#include <iostream>

using namespace std;

int main()
{
    int nr, i;

    cin >> nr;

    for ( i = 1 ; i < nr ; i++ )
    {
        int aux = i, suma_patrate_cifre = 0;

        while ( aux )
        {
            suma_patrate_cifre += ( aux % 10 ) * ( aux % 10 );
            aux /= 10;
        }

        if ( i == suma_patrate_cifre )
        {
            cout << i << " ";
        }

    }
    return 0;
}

9.

#include <iostream>

using namespace std;

int main()
{
    int nr, Fibo[100], i = 1;

    Fibo[0] = 0;
    Fibo[1] = 1;

    cin >> nr;

    do
    {
        i++;
        Fibo[i] = Fibo[i-1] + Fibo[i-2];
    } while ( Fibo[i] < nr );

    if ( Fibo[i] == nr )
        cout << "DA";
    else
        cout << "NU";

    return 0;
}
  • Upvote 1

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.