mechanical engineer tries to learn c
Hi! I'm a mechanical engineer student at BUTE. I'd really appriciate hints on how to make programs in c. Tutorials, quizzes, and more.
I want to make a program, which randomly generates 50 points in a Descartes-coordinate system, and connect them with lines, to form a VALID shape. the main goal is it's area (the shape's).
How genearte random numbers?
Any programming book will give you an example function. Do you have a compiler and are you familiar at all with the language? If you're running Linux, you should have installed a C compiler (cc) or probably a C++ compiler (gcc). Do a "whereis gcc" from the command line to see if you have it. If not, you will need to install it. Then it is a matter of editing your program and then from the command line, typing:
>gcc -o myprogram program.c <ENTER>
where program.c is your edited file and myprogram is the name of the program you're creating (the executable). In Windows these programs end with ".exe". In Linux it doesn't have to.
This will run the program through the preprocessor, compile and link standard libraries and create the executable module, "myprogram". Then you can just type:
and the program will run.
There are some built-in functions that come with a C compiler and rand() is one of them. I recommend "C Primer Plus" by The Waite Group if you already know a little about it. If you're really new, Look for something for newbies like "C By Example" by Greg Perry. Also, if yoiu're running Linux, get a Linux or Unix book to help with editing, compiling, linking, etc.
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
To generate random numbers there is the function:
in stdlib.h header file.
|All times are GMT -5. The time now is 07:22 PM.|