Jump to content

LOGIC

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by LOGIC

  1. thank you very much guys.

    I forgot to mention that I am practicing writing algorithms by induction and that was one question the instructor gave us :D.

     

    After some tries I relied that the best way to write it recursively is to save the returned value and add the next returned to it by using a variable defined out side the function, but the problem was How could I make the first call for the function returns the value in that variable and make other calls return the square?

     

    I got some help from a friend and end up with this function

     

    int i,z,f;
    bool m=false;
    
    int sqr(int n)
    {
       int i,j=0;
       if(n>1)
       {
              if(!m)
              {
              z=n;
              m=true;
              }
              i=sqr(n-1)+n+n-1;
              f=f+i;
              if(n==z)
              return f;
              else
              return i; 
       }
       else
       return f=1;
    }

     

    thank you very much, your posts were very helpful

  2. Hi

     

    I have tried to write program to calculate the sum of squares of number from 1 to n without using multiplication and it is supposed to be the efficient.

     

    I end up with this function that calculate the square of a number recursively and I made iterative function to calculate the sum of the squares but when it come to write the sum function recursively I could not do it.

    Take a look.

     

    c code for find the square

    int sqr(int n)
    {
       if(n>1)
       {
    
              return sqr(n-1)+n+n-1;
       }
       else
       return 1;
    }

     

    c code for the itritive sum square function

    int sumSqr(int n)
    {
       int i,j,f;    
       for(i=1;i<=n;i++)
       {
              if(i==1)
              {
                      j=1;
                      f=j;
              }
              else
              { 
                     j=j+i+i-1;
                     f=f+j;
              }
       }   
       return f;    
    } 

     

    HOW TO WRITE SIMILER FUNCTION RECURSEVLY?

  3. if there names like this "file1.txt,file2.txt,file3.txt...." and so on,you can use this simple code

     

    <?
    for($s=0;$s<100;$s++)
    { ?>
    <a href="/fictionall/file<?print $s; ?>.txt">File<?echo $s; ?>.txt</a>
    <? } ?>

  4. try to find the difference brtween level three and the other level.

    it is not in the source.

     

    I am stuck in novice level2 :rolleyes:

     

    I realize that i sould send to the server asking about its ip but I don't know HOW and telnet doesn't work !!

     

    is ther any helpful tool?

  5. I passed the hook but when I try to submit the proof I get this message

     

    You entered an incorrect password, tried to complete a wargame that doesn't exist or you have either already completed the wargame or you have a submission for that wargame pending.

     

    can any one help!

  6. hi

     

    I am Ahmed from Saudi Arabia , 21 years old.

     

    I am interested in any thing goes to computer.

    I study and live in KFUPM (King Fahd University of Petroleum and Minerals) in Dhahran

    I am in my third year studying computer science.

     

    not verry good in English although it is the language used in the university.

     

    you can find me in computer science section sea you there

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.