Author Topic: Problem ....  (Read 5697 times)

Offline SpiderMan

  • Single posting newcomer
  • *
  • Posts: 6
Problem ....
« on: June 18, 2010, 02:35:01 pm »
Hey. I am on my first programming year and i have a " big " problem : when i run a code, it gives me wrong result, or another program enter on  infinite cycle. But if i run this code on MinGW for example, it runs corectly. What's the problem ?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: Problem ....
« Reply #1 on: June 18, 2010, 03:31:17 pm »
of course,it must be something wrong in your codes.codeblcok is just a IDE.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline SpiderMan

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem ....
« Reply #2 on: June 18, 2010, 04:31:58 pm »
I don't think so, i say that i try the same code on another program ( MinGW studio ) and it works. And the same code on my friend's PC and he had the same error like mines.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Problem ....
« Reply #3 on: June 18, 2010, 04:37:39 pm »
Read
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Post a complete re-build log from both working and non working setup.


You failed to give enough info to get real help.

My wild guess is that you installed two different MinGW GCC and you installed them wrong or you configured Code::Blocks incorrectly.

Tim S.

Please read http://forums.codeblocks.org/index.php/topic,9996.0.html
Please include Compiler Versions, OS Versions, and Code::Blocks version in all requests for help!
« Last Edit: June 18, 2010, 04:45:02 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline SpiderMan

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem ....
« Reply #4 on: June 18, 2010, 06:25:45 pm »
I don't have MinGW personally, a friend have it an gave me help. I try on another computer both MinGW and Codeblocks, and the MinGW comport normally, but the CodeBlocks no.

[LE] I have Windows 7 x64 Ultimate, CodeBlocks 10.05 with no compiler updates ( the compiler is defaults ) 
« Last Edit: June 18, 2010, 06:27:18 pm by SpiderMan »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Problem ....
« Reply #5 on: June 18, 2010, 06:27:23 pm »
Bye, you still do not give enough info.
You say you have no compiler; therefore it will NOT compile if you are telling the truth.
Assuming you install a compiler; please give path to compiler and post a full compiler build log for someone else to try to help you.

Tim S.

PS: Sorry if your Language is not English; but, your post implies you never install a compiler.
« Last Edit: June 18, 2010, 06:38:22 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline SpiderMan

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem ....
« Reply #6 on: June 18, 2010, 06:43:56 pm »
I installed the CodeBlocks default compiler ... the program compiled, run but it didn't gave the correct result. And i run with MinGW ( a friend ) and it worked, and sorry, i forggot to say that i have CodeBlocks too  :P
« Last Edit: June 19, 2010, 07:21:40 am by SpiderMan »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Problem ....
« Reply #7 on: June 18, 2010, 07:51:02 pm »
Read
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Post a complete re-build log from both working and non working setup.

You failed to give enough info to get real help.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline SpiderMan

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem ....
« Reply #8 on: June 19, 2010, 07:17:09 am »
Ok, now i'll try to make you understanding my situation. Now i paste you my code :
Code
# include <fstream>
# include <cstring>
# include <cmath>
using namespace std;

#define MAX 105

int N[MAX], i[MAX] ;
int j;
char c[MAX];

ifstream f("free.in");
ofstream g("free.out");

void atrh (int A[], int B[]) // A <- B
{
    for (int i = 0; i <= B[0]; ++i) A[i] = B[i];
}

void add (int A[], int B[]) // A <- A + B
{
    int i, t = 0;

    for (i = 1; i <= A[0] || i <= B[0] || t; i++, t /= 10)
        A[i] = ( t += ( i <= A[0] ? A[i] : A[i] = 0 ) + ( i <= B[0] ? B[i] : B[i] = 0 ) ) % 10;

    A[0] = i - 1;
}

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

    for (; A[0] > 1 && !A[A[0]]; A[0]--);
}

inline int comp (int A[], int B[]) // A ? B , ? == <, >, =
{
    while (A[0] && !A[A[0]]) A[0]--;
    while (B[0] && !B[B[0]]) B[0]--;

    if (A[0] < B[0]) return -1;
    else if (A[0] > B[0]) return 1;
    for (int i = A[0]; i > 0; --i)
        if (A[i] < B[i]) return -1;
        else if (A[i] > B[i]) return 1;
    return 0;
}

void atr (int A[], long long X) // A[] <- X
{
    for ( A[0] = 0; X ; X /= 10)
        A[++A[0]] = X % 10;
}

void atr0 ( int A[] )
{
    A[0] = 0;
}

void mulmare (int A[], int B[]) // A <- A * B
{
    int i, j, t, C[MAX];        // C <- A * B

    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[i] * B[j] ) % 10;
        if ( i + j - 2 > C[0] ) C[0] = i + j - 2;
    }

    memcpy(A, C, sizeof(C));   // A <- C
}

void Shr (int A[], int Count) // A <- A / ( 10 * Count )
{
    memmove ( &A[1], &A[Count + 1], sizeof(int) * ( A[0] - Count ) );

    A[0] -= Count;
}

void Shl (int A[], int Count) // A <- A * ( 10 * Count )
{
    memmove ( &A[Count + 1], &A[1], sizeof(int) * A[0] );
    memset ( &A[1], 0, sizeof(int) * Count );

    A[0] += Count;
}


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

void impmare (int A[], int B[], int C[]) // C <- A * B rest R
{
    int R[MAX];

    R[0] = 0, C[0] = A[0];

    for (int i = A[0]; i ; i--)
    {
        Shl (R, 1), R[1] = A[i];

        for (C[i] = 0; comp(B,R) != 1 ; ++C[i], sub(R, B)) ;
    }

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

    A[0] = i - 1;
}

void citire(int x[],char a[])
{
    x[0]=strlen(a);
    for ( int i = x[0] -1; i >= 0; --i )
        x[i+1]=a[x[0]-i-1] - '0';
}

void write( int A[] )
{
    if ( A[0] == 0 ) g << "0";
    else for (int i = A[0]; i ; --i) g << A[i];
    g << "\n";
}

void radical_2 ( int A[], int B[] )
{
    int AUX = 0 , i;
    int C[MAX], D[MAX], E[MAX], F[MAX];

    if ( A[0] & 1 ) AUX = A[A[0]], i = A[0] - 1;         // formez prima pereche
    else AUX = A[A[0]] * 10 + A[A[0] - 1], i = A[0] - 2;

    int aux = (int) sqrt(AUX) ;                          // aflu nr. cel mai apropiat de prima pereche

    atr (B, aux);                                        // atribui rezultatului nr. aflat anterior

    if ( A[0] == 1 || A[0] == 2) return ;                // daca nr. are 1, 2 cifre, opresc

    AUX -= aux * aux;                                    // fac scaderea

    atr(E, AUX), Shl(E, 1), atr(F, A[i]), add(E, F);     // E = AUX, E *= 10, E += A[i];
                                                         // adica formez noul numar, adaugand urm. pereche de cate 2 cifre
    Shl(E, 1), atr(F, A[i - 1]), add(E, F);              // E *= 10, E += A[i - 1];
                                                         // la fel, formez noul numar adaugand cea de-a doua cifra
    atrh(C, E), atrh(F, B), mul(F, 2), atrh(E, F);       // dublez pe E

    i -= 2;                                              // scad 2 unitati, adica cele 2 cifre atribuite

    atrh(D, C), Shr(D, 1), impmare(D, E, D);             // aici scap de ultima cifra a nr. si o impart la E

    int U[] = {1, 9};                                    // vector auxiliar ce reprezinta cifra 9
    int Z[] = {1, 1};                                    // vector auxiliar ce reprezinta cifra 1

    if (comp(D, U) == 1) atr(D, 9);                      // daca cumva ultima cifra pe care trebuie sa o adaugam la
                                                         // rezultat e > 9, atunci ii atribuim valoarea maxima, 9
    Shl(E, 1), add(E, D), mulmare(E, D);                 // E *= 10, E += D, E *= D
                                                         // adica adaug la E cifra D si inmultesc nr. format cu D
    while ( comp(E, C) == 1 )     // daca E > C, adica ca si numarul format din adaugarea perechilor de cate 2 cifre
          sub(D, Z), atrh(F, B), mul(F, 2),  atrh(E, F),  Shl(E, 1),  add(E, D), mulmare(E, D);
                // atunci refac numarul, adica scad o unitate la numarul D si refac operatiile
    sub(C, E);  // fac scaderea, adica numarul format E il scad din C, care a fost numarul format din ad. celor 2 cifre

    Shl(B, 1), add(B, D);    // B *= 10, B += D , adica adaug la rezultat cifra D

    for (i = i; i ; i -= 2)  // aici merg cu un for care reprezinta pozitia de unde voi adauga cele 2 cifre
    {
        atr(E, A[i]), atr0(F), Shl(F, 1), add(F, E);   // de aici operatiile se reiau
        atr(E, A[i - 1]), Shl(F, 1), add(F, E);

        Shl(C, 2), add(C, F), atrh(F, B), mul(F, 2), atrh(E, F);

        atrh(D, C), Shr(D, 1), impmare(D, E, D);

        if (comp(D, U) == 1) atr(D, 9);

        Shl(E, 1), add(E, D), mulmare(E, D);

        while ( comp(E, C) == 1 )
              sub(D, Z), atrh(F, B), mul(F, 2),  atrh(E, F),  Shl(E, 1),  add(E, D), mulmare(E, D);

         sub(C, E);

         Shl(B, 1), add(B, D);
    }
}

int main()
{
    f >> c;

    citire(N,c);

    radical_2(N,i);

    sub(N,i);

    write(N);

    return 0;
}

I want you ( or anybody who want to help me ) to run this code. But first, create a input called free.in, in the same directory with the code. ( the code is *.cpp ) Now, in the file newly created introduce next : 999192934845325420052052502005230001
( it's just a test ) . Now tell me what's the result in free.out, if you have .

[LE] And sorry for the code's commentary, it's in romanian.
« Last Edit: June 19, 2010, 07:18:59 am by SpiderMan »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Problem ....
« Reply #9 on: June 19, 2010, 09:14:50 am »
If your code does not compile correctly or does not behave as you expect, it's either a compiler or a programming problem.

Both are not related to Code::Blocks.

C::B is not a compiler, it's "just" an IDE that calls the compiler.

Your question violates our forum rules (only C::B related questions allowed).

Topic locked !