how a C program will interact with the OS,how a worm would?
That's up to you to figure out. C or any other language is just a tool. You have to make it do what you want. I'm not sure what you mean by interact with the OS. You can have C use system calls(functions that the OS provides). This would be useful in hooking the keyboard(IE listening to all the keystrokes made by the user). I'm going to be honest. This is something that is going to take a while to learn. To make a real worm will take quite a bit of knowledge so it's not going to be obvious how to make one after learning C.
Creating an algorithm is easy. An algorithm is just a series of steps that complete a task. Technically a cook book is a bunch of algorithms to cook food. An example of a common algorithm(computer related) would be a sorting algorithm(bubble sort, selection sort, ect).
To give you an idea of what a VERY basic worm would do:
1. First it needs to do something. This is what the worm is here to do. I guess this could be optional if you just wanted it to spread itself and do nothing else.
2. It needs to spread itself. I'm no expert(or even novice for that matter) but I see two main ways to do this. Find a common exploit that is rarely patched and use that to spread(hard way). Or use people's stupidity to spread itself(easier way). This would be something similar to listening to all the keystrokes and waiting for something in the form of <letters>@<domain>. The the next thing typed is most likely a password. Use this information to email itself to the contacts of this email.
This is the bare minimum and it still would be a very large program. Another very necessary feature would be avoiding antivirus. This alone would be huge but probably very interesting to implement. There are probably a lot more to this but these could be questions to ask yourself "How would I do this?"
accesing/opening files on the computer, wouldnt that be a batch file?
I think you're a little confused about batch files. Batch is a completely different language than C. A batch file can manipulate files and a C program can manipulate files. Opening files in C is pretty easy(google).
I realize that this probably isn't what you're looking for but you need to realize that this isn't something that can be explained in a few paragraphs. You are asking good questions though.
