Posts for Swedishmartin

1 2 3
11 12
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Project Euler, challenge two. I'm stuck.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.
#include <stdio.h>

int main()
{
	int add = 0;
	int a, b = 1;
	int c;

	for(; b < 4000000; )
	{
		c = b;
		b += a;
		a = c;

		if((b % 2) == 0)
		 add += b;
	}

	printf("%i", add);
	return 0;
}
It prints 0, and I don't know why.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Blublu wrote:
That's like saying don't buy new food if your old food goes bad.
You don't need computers to live. Also, old computers are still usable. I don't understand your metaphor, to be honest.
Blublu wrote:
I fail to see how that's any different from not throwing them away, environmentally speaking. They'll be thrown away or recycled eventually either way, so what's your point?
I meant if you got sickened by seeing them, why not just get rid of them? Also, your insistence of buying new computers despite of your guilt about your old ones is hypocritical. You should either be ignoring the climate or helping it, preferably the latter.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Blublu wrote:
My old computers tend to sicken me by the time I get a new one
Well, don't get new ones then. That way you won't additionally contribute to global warming and the growing trash problem in development countries. If you feel that it's absolutely necessary for you to buy new computers, just throw the old ones on the dump and forget about them.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Bisqwit wrote:
static void AddNode(node** tree, node* newnode) //tree is a double pointer which makes it twice as good
Is this how it works?
Experienced Forum User
Joined: 11/26/2005
Posts: 285
nfq wrote:
he couldn't stay in sunlight because he was a vampire.
And a zombie.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
nfq wrote:
If you want to know what animal that is similar to you, just ask yourself what your horoscope is. Most horoscopes are animals.
Keeping scorpions seems like a bad idea. And to the cat people: Yeah, it seems I was wrong. If cats are as good as you say, they are absolutely better than dogs. Nevermind animals though. Let's get to the real discussion: religion. (THIS IS A JOKE DON'T TALK MORE ABOUT RELIGION MAYBE GOD EXISTS MAYBE HE DOESN'T BUT ANYWAY YOU WON'T CONVERT THE OTHER SIDE IN ANY CASE SO JUST DROP IT)
Experienced Forum User
Joined: 11/26/2005
Posts: 285
You say that you like cats because they're "understandable" (this I interpret as "intelligent"), and I've heard you say before that dogs are disgusting and unpleasant. However, I think that cats are not intelligent, they only seem to be since they aren't pack animals and therefore can live independently. This is the reason I can't fathom why you would keep a cat as a pet - you buy pets because you need company, but why buy one that doesn't need company itself? Also, dogs can be disgusting but I have never found them unpleasant. In any case, my dog greeting me when I come home (which cats don't do as far as I know) makes up for anything else he does. To sum it up: Dogs are awesome. Cats? Not so much.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Well, looks like I've gotten into a problem too difficult for me. I should start working on pointers instead, and I can pick this up later (by the end of summer, perhaps?). Also, I must stop posting so much in this thread. By the way, Warp: is
for(int i = 0;;)
even legal C?
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Bisqwit wrote:
Consider what happens to the loop terminating condition "p < LTH" when you execute "p = -n;". When do you suppose the loop ends? The simplest solution for making this _work_ involves the modulo operator, but I'm providing thought fodder here, not the solution handed on a silver platter…
I'll take a look at this; thanks. I don't know if I can use your example, because eyeing over it it seems a bit difficult for my level. Maybe it isn't, I'll see.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Hey, I tried to make a program that prints this:
Hello, World! 
ello, World! H
llo, World! He
for 30 lines, and I came up with this:
#include <stdio.h>
#define LTH 13

int main()
{
	int arr[LTH] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', ' '};
	int n, p;
	
	for(n = 0; n < 30; n++)
	{
		for(p = 0; p < LTH ; p++)
		{
			printf("%c", arr[p + n]);
			if(p + n == LTH)
			 p = -n;
		}
	printf("\n");
	}
	
	return 0;
}
The printed text is something like
ello, World!
             ello, World!
                          ello, World!
printing non-stop. What did I do wrong?
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Thank you! I now know more. :)
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Thank you too, Warp.
Warp wrote:
Then there are also the so-called static libraries. ... disk space is saved (because the object files of the library are not copied in your disk for each program source code which uses that library).
But wouldn't using many static libraries be more space-consuming than using one dynamic? Oh, and by the way: What if I wanted to make an executable without any library (including libc) dependencies? Would that be simple? Would it even be possible?
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Thank you for clearing that up. :)
Experienced Forum User
Joined: 11/26/2005
Posts: 285
nfq wrote:
Why do people laugh at evolutionists: http://www.youtube.com/watch?v=9f7Zv18urU0&feature=channel_page
If you've seen the "laugh at creationists" videos nfq linked to it becomes quite clear that it's a parody, and an amazingly funny one as well. "Well, the reason Hitler did the evil things he did was because he was a Roman Catholic." A video by the same user: I love you; but you are Satan
Experienced Forum User
Joined: 11/26/2005
Posts: 285
I have a question! My question is regarding the C libraries. I've been reading about the details of how they work and so on. I've been reading a bit on Wikipedia about them, but their reason of existence eludes me.
C Standard Library wrote:
The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and string handling, in the C programming language.
Okay, so the routines in libc (if I may call it that) are defined in a compiled library file, as opposed to completely in header files. That is, the libc functions aren't compiled into the program, but the program is linked to them instead.
C (programming language) wrote:
The C programming language uses libraries as its primary method of extension. In C, a library is a set of functions contained within a single "archive" file. Each library typically has a header file, which contains the prototypes of the functions contained within the library that may be used by a program, and declarations of special data types and macro symbols used with these functions.
The "archive" file referred to is a library, I assume. The header files contains code to access the functions in the library.
C (programming language) wrote:
Since many programs have been written in C, there are a wide variety of other libraries available. Libraries are often written in C because C compilers generate efficient object code; programmers then create interfaces to the library so that the routines can be used from higher-level languages like Java, Perl, and Python.
Lots of libraries are used, not just libc. But why would you use libraries? Why not just compile the functions into the program? Also, how are libraries compiled? Is library source code available (for example for the GNU Standard Library)? Would it be possible to make a "stand alone" program in C, that used no external libraries? If so, how? Someone please answer my questions! Thanks in advance.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Experienced Forum User
Joined: 11/26/2005
Posts: 285
I couldn't name one. Thankfully, being crap at trivia isn't much to worry about.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Yes, I understand it now. Thanks. :)
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Warp wrote:
Can I ask you why you want to learn C, rather than, for example, C++, C# or Java?
I'm really a newb, so this may be wrong, but I've heard that: C++ is harder to learn for beginners (I've only known BASIC before) C# is basically limited to Microsoft hardware unless you use Mono Java is harmful to beginners Or, to put it simply, why not?
Warp wrote:
As for your question, can you be a bit more specific about what is it that you don't understand about arrays? Also, are you talking about static arrays or dynamically allocated ones? (Do you know the difference?)
I don't understand how they are implemented, the definition of 'array', and what they possibly could be used for.
Derakon wrote:
Knowing C is a bit like knowing assembly, in that it gives you a lot of insight into how computers "actually work" than higher-level languages do.
This is part of the reason I wanted to program in the first place. I'd rather learn how a computer handles logic, rather than making a game or something along those lines.
amaurea wrote:
An array is a continuous section of memory containing data of the same type...
Thank you for the explanation. I didn't get much of it, though. I'll read up on pointers and re-read your post. :)
Experienced Forum User
Joined: 11/26/2005
Posts: 285
Hi! I'm back, and I need more help with C! At Christmas I recieved The C Programming Language, so I'm learning from that now, rather than internet tutorials. I'm currently 'stuck' at the section regarding arrays; I really can't understand what they are. Someone! Please tell me how they work, and what they're used for!
Experienced Forum User
Joined: 11/26/2005
Posts: 285
RT-55J wrote:
The videos were the best part of the game.
BEFORE THERE WERE LEMONS
Experienced Forum User
Joined: 11/26/2005
Posts: 285
This site says you should get a CycloDS.
Experienced Forum User
Joined: 11/26/2005
Posts: 285
windows sucks but linux torvalds is sooooooooooooo hot!!!
Experienced Forum User
Joined: 11/26/2005
Posts: 285
har har har
Experienced Forum User
Joined: 11/26/2005
Posts: 285
superjupi wrote:
Having not watched the video, what is it that separates it from other whois tools, like this one?
I was about to write "it gives a nice list of results" until I checked your link. Thanks, just what I was looking for! :)
1 2 3
11 12