Skip to content
View in the app

A better way to browse. Learn more.

GAMELIFE România

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C/C++] Operatii pe numere mari

  • Members

Operatii pe numere mari

  In continuare voi prezenta cum se pot realiza operatii pe numere mari cu foarte putine linii de cod. In general, multi programatori se complica la aceste operatii, desi nu este nevoie! Vom considera ca numerele mari sunt vectori in care elementul de indice 0 indica lungimea numarului, iar cifrele sunt retinute in ordinea inversa decat cea a citirii.

void add(int A[], int B[])

{
      int i, t = 0;
      for (i=1; i<=A[0] || i<=B[0] || t; i++, t/=10)
              A = (t += A + B) % 10;
      A[0] = i - 1;
}

    Inmultirea unui numar mare cu un numar mic:

void mul(int A[], int B)
{
      int i, t = 0;
      for (i = 1; i <= A[0] || t; i++, t /= 10)
              A = (t += A * B) % 10;
      A[0] = i - 1;
}

        Inmultirea unui numar mare cu un numar mare:

void mul(int A[], int B[])
{
      int i, j, t, C[NR_CIFRE];
      memset(C, 0, sizeof(C));
      for (i = 1; i <= A[0]; i++)
      {
              for (t=0, j=1; j <= B[0] || t; j++, t/=10)
                      C[i+j-1]=(t+=C[i+j-1]+A*B[j])%10;
              if (i + j - 2 > C[0]) C[0] = i + j - 2;
      }
      memcpy(A, C, sizeof(C));
}

        Scaderea a doua numere mari:

void sub(int A[], int B[])
{
      int i, t = 0;
      for (i = 1; i <= A[0]; i++) {
              A -= ((i <= B[0]) ? B : 0) + t;
              A += (t = A < 0) * 10;
      }
      for (; A[0] > 1 && !A[A[0]]; A[0]--);
}

 

         Impartirea unui numar mare la un numar mic:

void div(int A[], int B)
{
      int i, t = 0;
      for (i = A[0]; i > 0; i--, t %= B)
              A = (t = t * 10 + A) / B;
      for (; A[0] > 1 && !A[A[0]]; A[0]--);
}

        Restul unui numar mare la un numar mic:

int mod(int A[], int B)
{
      int i, t = 0;
      for (i = A[0]; i > 0; i--)
              t = (t * 10 + A) % B;
      return t;
}

 

Sursa: Click
 

Edited by Achilles

Featured Replies

No posts to show

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.