"JS" <dsa.@asdf.com> wrote in message news:cn**********@news.net.uni-c.dk...
I have done the following: New Project -> Console Application -> C Project.
Then I get the following text:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
system("PAUSE");
return 0;
}
But where do I write my own C code? I have written the following code:
void c(unsigned int n) {
while (n > 1)
if ((n & 1) == 0)
n = n/2;
else
n = 3 * n + 1;
}
But where should I put it and how do I compile it?
As you've been told already, you should ask C questions in a C newsgroup.
But, this could just as easily be a C++ question, so I'll give you some
pointers:
First, one place to put that function is just above your main() function.
Then, you can call it from main(). There are other ways to arrange
programs, which you'll need to learn, but this will work for now.
Second, leaving aside analysis of what the function c does internally, you
should note that anything that it does to n internally will not be relected
back to the variable that is passed to the function, because n, in that
function, is simply a local copy of the value passed in. That's because you
passed it "by value". If you want to actually change the value that was
passed in (from main, for example), you'll need to pass it "by reference".
-Howard