Thread: Fibbonacci Code

  1. #16
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by SilverSteel
    "if NOT EQUAL to any numerical value"
    It's in the FAQ:
    http://faq.cprogramming.com/cgi-bin/...043284385#opt3

    A related good read:
    http://home.att.net/~jackklein/c/code/strtol.html

    But where is that icky thing I wrote a while ago?
    [search...]
    [search...]
    [search...]
    Code:
    #include<stdio.h>
    #include<string.h>
    char*q(char*o){char*s=o,*e=s+strlen(s)-1;while(s
    <e){char t=*e;*e--=*s;*s++=t;}return o;}char*u(a
    ,b,c,n)char*a,*b,*c;size_t n;{char*d=a,*e=b,*f=c
    ;int x=0;a=q(a);b=q(b);for(;;){int y=0;if(c>=&f[
    n-1]){return 0;}if(*a){y+=*a-'0';++a;}if(*b){y+=
    *b-'0';++b;}y+=x;x=y>10;if(!y&&!*a&&!*b){break;}
    else if(y>9){x=1;y-=10;}else{x=0;}*c++=y+'0';}*c
    ='\0';;strcpy(d,q(e));strcpy(e,q(f));return(f);}
    char A[1024]="0";char B[sizeof(A)/sizeof(*A)]="\
    1";char C[sizeof(A)/sizeof(*A)];;int main(){char
    f[]="f(%d)= %s\n";int i=0;printf(f,i++,A);printf
    (f,i++,B);while(i<=10000){char*c=u(A,B,C,sizeof(
    C));if(!(c)){break;}printf(f,i++,c);}return(0);}
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  2. #17
    Registered User theFOX's Avatar
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    6

    Talking

    Strange, i tried it before, and it gives me the same error every time ( invalid conversion from void* to long long int* ).

    Actually, i didn't see it without casting before, n e one tried it ??



    BTW, for the factorial thingy, i think you can solve it by specifying the number of times each prime number occures in the value of the factorial, then you can calculate the value by using a char array ( lattice multiplication ), then print it.

    Code:
          
         5! = 3 1 1 ( 3 twos, 1 three, 1 five = 2^3 * 3^1 * 5^1 = 120)
       53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1 1
      100! = 97 48 24 16  9  7  5  5  4  3  3  2  2  2  2  1  1  1  1  1  1  1  1  1  1  1
    One problem that may face you is the power issue, of course 2 ^ 97 is a mad thing to be done, but, you can get around this by dividing the power and using strings to store each value ( lattice mul again ), then print your char array !!

    Land here for more info >> http://www.answers.com/topic/multiplication-algorithm

    Regards,
    theFOX

  3. #18
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    >>Strange, i tried it before, and it gives me the same error every time ( invalid conversion from void* to long long int* ).

    Compile as C, not C++, a C++ compiler will call that code dodgy - very cool though Dave!
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  4. #19
    Registered User theFOX's Avatar
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    6

    Talking

    hehe, i always forget to do that !!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM