ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
>myprogram <ENTER>
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.