ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

Why Compilation Error??(Please Help!)
Posted by simply 28 Feb 2003 14:24
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void)
{
    int i;
    long N;
    long term;
    int *a;
    scanf("%ld",&N);
    a=(int *)malloc(N*sizeof(int));
    for(i=0;i<N;i++){
        scanf("%ld",&term);
        a[i]=(int)(1+(int)(sqrt(8*term-7))-sqrt(8*term-7));

    }
    for(i=0;i<N;i++)printf("%2d",a[i]);
    return 0;
}

Thank you!
Re: Why Compilation Error??(Please Help!)
Posted by chemik 1 Apr 2003 03:43
a[i]=(int)(1+(int)(sqrt((float)(8*term-7)))-sqrt((float)(8*term-7)));

but
long int have 4 bytes
and, 2^31*8 = overflow ;)
Re: Why Compilation Error??(Please Help!)
Posted by simply 12 Apr 2003 09:43
> a[i]=(int)(1+(int)(sqrt((float)(8*term-7)))-sqrt((float)(8*term-
7)));
>
> but
> long int have 4 bytes
> and, 2^31*8 = overflow ;)
thank you!