Jump to content

Recommended Posts

  • Moderators
Posted

Asta mi-a iesit acum, pare cam sf :))

#include <math.h>

int sub(int n)
{
    int nr_cifre = log10((double) n) + 1, i, cifra;
    int aux = 0;
    for (i=1 ; i <= nr_cifre ; i++)
    {
        cifra = n / (int) pow(10.0, (double) nr_cifre - i) % 10;
        if (cifra != 0)
        {
            aux = aux * 10 + cifra;
        }
    }
    return aux;
}
  • Upvote 1

Posted

O alta varianta , mai usor de inteles(am facut intreaga problema) in Code::Blocks. Desigur , acum Courage o sa-mi zica de eficienta (cin/cout) :)) , dar asa e mai usor de inteles:

#include <iostream>
int n,m,i,a[100],y;
using namespace std;
int sub()
{
    while(n)
     {if(n%10!=0)
      a[++m]=n%10;

    n=n/10;}
    for(i=m;i>=1;i--)
      y=y*10+a[i];
      return y;
}
int main()
{
   cin>>n;
   cout<<sub();
}

b_350_20_323957_202743_F19A15_111111.png

  • Moderators
Posted

Numarul maxim pe care o variabila de tip int o poate lua este

#include <iostream>
#include <limits>

int main()
{
    std :: cout << std :: numeric_limits<int>::max();
    return 0;
}

2147483647

 

Poti declara vectorul a de 10 elemente. Nu au rost 100. Ocupi memorie degeaba :));

Posted

da, am pus asa ca sa poti modifica in caz de nevoie tipul de date: 

 

int n,m,i,a[100],y;

 

daca era unsigned long long se modifica marimea maxima a vectorului si primeai eroare . Asa am pus la siguranta , ca sa nu-ti dea eroare si sa nu stii de unde ;)

 

Am facut un model de problema ca sa se inteleaga mai usor , daca e sa ne gandim si la eficienta , problema arata altfel , mai dificil :D

  • Upvote 1

b_350_20_323957_202743_F19A15_111111.png

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.