Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Programming with NTL; help required! (http://www.go4expert.com/forums/programming-ntl-help-required-t17695/)

 ikj 25May2009 20:33

Programming with NTL; help required!

im writin this code to generate the powers of 2 n 3 ie (2^i)*(3^j) with i and j from 0 to 64 and since im using NTL i dont have to worry bout system storage constraints.

here's my code:
Code:

``` #include<NTL/ZZ.h> #include<NTL/vec_ZZ.h> NTL_CLIENT #define SIZE_OF_INTEGER 64 vec_ZZ sort_a(vec_ZZ a, long l) {  ZZ temp;  for(long i=0;i<l;i++)  {   for(long j=i;j<l-i-1;j++)   {   if(a[i]>a[j])   {     temp=a[i];     a[i]=a[j];     a[j]=temp;   }   }  }  return a; } main() {       ZZ c,n,d;       vec_ZZ a,b;       a.SetLength(power_long(SIZE_OF_INTEGER,2));       ZZ v;  v=power_long(2,SIZE_OF_INTEGER);  long    x=0;       for(long i=0;i<SIZE_OF_INTEGER;i++)       {           for(long j=0;j<SIZE_OF_INTEGER;j++)           {               d=(power_long(2,i)*power_long(3,j));       if(d<v)   {   a[x]=d;   cout<<a[x]<<endl;   x++;   }   else   break;           }       }  sort_a(a,a.length());  cout<<endl<<x<<endl;  for(long k=0;k<a.length();k++)   cout<<a[k]<<endl; }```

 xpi0t0s 26May2009 02:49

Re: Programming with NTL; help required!

How exactly isn't it working properly? What does it do that you don't expect, or what does it not do that you expected it would?

 ikj 26May2009 09:32

Re: Programming with NTL; help required!

i want it to print the powers of 2 and 3 ie (2^i)*(3^j) with i and j from 0 to 64
ie the output shud be
1,2,3,4,6,8,9,12,15,16,18.....
but i dont get that output; wat i get is something else, i get some big negative number (1 followed by 31 zeores in binary form) 64 times and then alot of zeroes instead of what i've mentioned above..

 xpi0t0s 26May2009 15:44

Re: Programming with NTL; help required!

3^(SIZE_OF_INTEGER-1) isn't going to fit into a SIZE_OF_INTEGER-bit integer...

 All times are GMT +5.5. The time now is 14:19.