Thread: question ?

  1. #31
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This second one doesn't requires too much thought to say it's unsolvable. Chess problems aren't the same.
    That's absurd. I was really going to not post a reply, because it's obvious you're just trolling. However, this statement is just absurd.

    First off, the problem is solvable within the stated requirements. Three solutions have been showen, all of which actually produce the required output in one form or another.

    If the provided answers are "wrong", it's because the original poster's requirements were not spelled out clearly enough. Three answers meet the stated criteria.

    "Chess problems aren't the same."

    What? What exactly is a 'chess problem'? You make pretty big claims here and provide absolutely no backing what so ever.

    Here's a "chess problem":
    1) Show an ascii representation of a chess board in its initial state.
    2) Black going first, make one move for each color.

    There, you have a "chess problem", which is definately easier than the original question in this post. There is no need for anyone to actually post code, because this is a trivial "chess problem".

    Again, your statement is absurd.

    Quzah.
    Hope is the first step on the road to disappointment.

  2. #32
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    No more off topic posts please, they'll end up in the bin.

    >>You didn't prototype func1 (or give it a return type)
    It was prototyped (slightly incorrectly, but it was there). Look at the start of main():
    >>int n, func1();
    should really have been:
    >>int n, func1(int);

    >>m = t || exit(0); /*this is a short circuit operation using or*/
    The use of the "or" (||) still constitutes a "test condition" which your requirements state is not allowed.

    >>exit(0)
    requires stdlib.h. Of course, if you include this header, the program won't compile at all, because, as Salem said, exit() returns void and therefore cannot be used as part of a conditional test.

    >>recursion
    As already stated, this constitutes a loop, and is also not allowed.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #33
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define N 6
    #define PI 3.14159265358979323846
    
    int main()
    {
    	printf("%.2f\n",((N-1)*sin(0.00*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.05*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.10*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.15*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.20*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.25*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.30*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.35*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.40*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.45*PI))+1);
    	printf("%.2f\n",((N-1)*sin(0.50*PI))+1);
    	return 0;
    }
    This code prints out 11 numbers between 1 and N, inclusive. Define N in the code. (It wasn't specified that we had to print ALL the numbers between 1 and N)
    Away.

  4. #34
    Banned
    Join Date
    May 2003
    Posts
    124
    >First off, .... answers meet the stated criteria.
    Nop!

    >What? What exactly is a 'chess problem'? You make pretty big claims here and provide absolutely no backing what so ever.
    Well, i was not speaking about a programming chess problem, but about a problem on the reall chees board

    >There, you have a "chess problem", which is definately easier than the original question in this post. There is no need for anyone to actually post code, because this is a trivial "chess problem".
    This is not a chess problem. This is not a problem even!
    After all, ok, there are easier chess problems some other are harder. Like maths, physics and programming etc.

  5. #35
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    what about that "recursive apporach" ???
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  6. #36
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    A couple people have done it recursively. The clearest is AProg's, but he used an if, so it doesn't meet the criteria.

    >>reall chees board
    I had a reall chees board once, but I spelled it like this: "real cheese board" except for when I spelled it like this "etrfl keaess bard" It was this great big board, and it was made entirely out of cheese. There was some blue cheese, some colby cheese, some cheddar cheese, some swiss, motzeralla, and limburgher. All the cheese lived happily together until the cheddar proclaimed itself king and said "checkmate." AProg, try to make sense man, and stay on the subject. It's a cool problem and requires you to think. Don't dis it.
    Away.

  7. #37
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    m = t || exit(0);

    ... is incredibly smart. Short curcuiting so that t is tested. If its over 0 then it keeps on going. Else, it exits the program. Unfortunatly it won't work as it is there. You have to cast the void into something an int or something (which C++ allows you to do). But the return doesn't even matter because by that time, the program exited. And even if it DID return, the return would be whatever is left in the 'eax' register (which is an int). (that of course is assuming an x86 computer). But still, it IS a test condition so you can't use it.

  8. #38
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    This is a modified version of one of the solutions provided in a link on the first page. This is C++ (not C) but its brilliant the way the original author did it. I modified it so that it will ask for n and fixed some errors.

    Code:
    #include <iostream>
    using namespace std;
    
    int n = 0;
    
    struct N
    {
        N() { cout << ++n << " "; }
    };
    
    int main()
    {
        int max;
        cout << "Enter n: ";
        cin >> max;
    
        N *nn = new N[max];
        delete [] nn;
    
        cout << endl;
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM