User Profile

Collapse

Profile Sidebar

Collapse
D_C
D_C
Last Activity: Oct 19 '06, 09:41 PM
Joined: Jun 20 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • D_C
    replied to How do i do partial sums?
    in C
    Code:
    int i;
    int sum = 0;
    for(i = FIRST_VALUE; i < STOP_VALUE; i++)
    {
      sum += f(i);
    }
    See more | Go to post

    Leave a comment:


  • D_C
    replied to need help to write a program
    in C
    Code:
    int factorial(int n)
    {
      int result = 1;
      while(n > 1)
      {
        result *= n;
        n--;
      }
      return result;
    }
    See more | Go to post

    Leave a comment:


  • D_C
    replied to calculate the horse's movement
    in C
    A horse can only cover one square in one move, and there are 64 squares, you start on 1 initially, so at a minimum it can take 63 movements. You could do this problem recursively and search for a solution.

    However, it may depend on the starting place too. If you just need to cover the entire board, it can be done. I suppose minimizing it would be the best answer.

    Code:
    int solve(int chess_board[][], int last_col, int last_row,
    ...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Can help me with the coding?
    in C
    You only need nRows, or nCols, not both. Replace
    Code:
    for (nRows = 0; nRows < m_nRows; nRows++)
    {
      for (nCols = 0; nCols < m_nCols; nCols++)
      {
        ...
      }
    }
    by
    Code:
    for(nRows = 1; nRows < m_nRows; nRows++)
    {
      if( matrix[nRows][nRows] != matrix[0][0] )
        // not a scalar matrix
    }
    // is a scalar matrix
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Write a nested loop to create following pattern
    in C
    I'm not sure what is supposed to happen for numbers greater than nine. This does the simpler case (with spaces in between).
    Code:
    int i = 1;
    int count = 0;
    while(i <= input)
    {
      while(count < ((2*input)+3))
      {
        if( ... )
          print a space
        else if( ... )
               print count
             else if ( ... )
               print either input or count
    ...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to falling number
    in C
    What is a falling number program? Can you give an example? Is it something like this?
    Code:
    Enter a number: 5
    
    5 
    4
    3
    2
    1
    See more | Go to post

    Leave a comment:


  • D_C
    replied to I Am Down With Viral And Need Help.
    in C
    You don't have the strength to do it? I don't think so...

    I'll still give you C++ code though that prints an integer as binary.
    Code:
    void printBinary(int input)
    {
      for(int i = 31; i >= 0; i--)
        cout << ((input && (1 << i)) >> i);
      cout << endl;
    }
    I haven't tested it, but it seems simple enough.
    See more | Go to post

    Leave a comment:


  • D_C
    replied to could you help about algorithm
    in C
    I completely blanked on answering his question. I did mine in C++. I'm not sure your stopping case is correct. I also use a 1D array. The recursion is similar, especially if you use a 2D array. I'll let you work at the recursive step.

    Also note that I past last_number and last index. That way, I know where I am in the matrix, and can test whether I may go up, down, left, or right.
    A hint: In the main loop I am guessing where...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to could you help about algorithm
    in C
    I think you misunderstood him. He said you have to go from the numbers from 1, 2, ..., 8, 9. I think he meant to say that one only move laterally (Up, left, down, or right). To clarify what he said, you can't move diagonally, like from square #1 to square #5, but you could go from square #2 to square #1 or #5 (or #3).

    After further thought, there is definately some rotational, diagonal, and directional symmetry. Each pattern can be...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Please Help with e^x estimating program
    in C
    The formula is summation (x^n)/n! and you are calculating summation (x^n)/x!. Change your parameter for factorial from x to n. You could also do an iterative version, it would be much faster.
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    
    int main()
    {
        cout << setiosflags(ios::fixed) << setprecision(5);
    
        double x;
        cout <<
    ...
    See more | Go to post

    Leave a comment:


  • Are you too lazy to Google it?

    Quick Sort
    Bubble Sort
    See more | Go to post

    Leave a comment:


  • D_C
    replied to could you help about algorithm
    in C
    I just implemented my own version of the program, 63 lines of code. Also, you need a third parameter. The first parameter can be the array with values (0 for empty else the number which occupies it), the last number placed, and the index where the last number was placed.

    I count forty solutions. Interestingly, the number of solutions from each starting point is
    Code:
    8 0 8
    0 8 0
    8 0 8
    . There may be a faster non-recursive way...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to could you help about algorithm
    in C
    First, does 1 have to start in the upper left corner? If not, you may have to call this function nine times, each time with one in a different corner.

    You need a 9 entry boolean array to keep track of which entries are occupied. Also, you need to pass which number was just placed. Then, for each number, recursively go up, down, left and right. However, if you will exit a boundary or it's occupied, don't visit it.

    If...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Help! Storing strings into arrays
    in C
    Are you using the STL string class? If so, you can call
    Code:
    reverse(s.begin(), s.end());
    to reverse the string.
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Please Help with e^x estimating program
    in C
    Code:
    double sum (double factors)
    {
            double sum;
            for (double n=1; n<=100; n++)
            [b]sum = pow(x,n)/factorial(x);[/b]
    
    return sum;
    }
    should be
    Code:
    sum += pow(x,n) / factorial(x);
    Also, the first term of the series is 1, so you could start the loop at 0 instead of assigning
    Code:
    estimate = 1 + sum(x);
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Poker Program
    in C
    When I did something like this in Java, I gave the cards a numeric value of 0-51. It made the comparisons for which type of hand easier. Modulo and division operations give the 2-A and suit.

    Also, I think "two high" through "six high" are unnecessary. A 2 is the lowest card you can have, if that's also your highest you should have 5 two's. If you have six high, and no pairs, then you have a straight.
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Program
    in C
    Here's a hint: If you define your program's entry point as int main(), then you can't do it. There are two parameters you need to identify, and one of the parameters has the information you need.
    See more | Go to post

    Leave a comment:


  • D_C
    replied to working with textfiles in c++
    in C
    Pseudocode for #1
    Code:
    open text file
    // it would be nice if it told you how many lines to make it
    while(not end of file)
    {
      str = get next line
      if(array full)
        make a bigger array
      insert str into next open spot in array
      increment index for next open
    }
    close the text file
    Pseudocode for #2
    Code:
    for(int i = 0; i < NEXT_OPEN_ENTRY; i++)
    {
      output each sentence
    ...
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Plz Help me! its Urgent!
    in C
    I would use four singly linked lists instead of an array. One would be for each corresponding value, -1 through 2. Then you can just iterate through each list. If you modify one, remove it from one list, and insert it into another. Each node should keep an artificial array index.
    See more | Go to post

    Leave a comment:


  • D_C
    replied to Help on permutation and combination.
    in C
    Some formulas may help.

    nPr or P(n,r) = n! / (n-r)!

    nCr or C(n,r) = n! / r!(n-r)!

    In other words, (nCr * r!) = nPr.
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...