![]() |
|
|
#1 (permalink) |
|
Cnsnnts - Stt f Mnd
Staff Member
|
Hi guys. I've recently started learning C. I have borrowed a good book from the library, and, as an exercise, I had to make a program to show the relative mass of an object at speeds close to c, for a rest mass of 1 kg. This is my program:
Code:
#include <math.h>
#include <stdio.h>
#define START 0.9*3e8
#define END 0.99*3e8
#define INC 0.01*3e8
double convert(double v)
{
double m, m0, c;
m0 = 1.0;
c = 3.0e8;
m = m0 / sqrt(1 - (v / c) * (v / c));
return m;
}
int main(void)
{
double v;
double mass;
for (v = START; v <= END; v += INC)
{
mass = convert(v);
printf("At velocity %f%% of c, an object of rest mass 1 kg weighs %f kg", v, mass);
}
return 0;
}
Code:
andrew@andrew-laptop:~/Documents/C$ gcc relmass.c -o relmass /tmp/cc4LgTLT.o: In function `convert': relmass.c:(.text+0x50): undefined reference to `sqrt' collect2: ld returned 1 exit status If it helps I am running ubuntu 9.04 with gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4). Can anyone tell me why this program won't compile, or spot any mistakes? Thanks for your help. |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Java] (Bi)Monthly Programming Challenge, anyone interested? | Mink | Computers and Games | 5 | 13-02-2009 04:05 PM |
| Programming Language | James | Computers and Games | 36 | 27-06-2008 09:44 PM |
| Favorite Programming Language | Dreamaker | Computers and Games | 16 | 30-04-2008 05:36 AM |
| Programming | Incomplete Dude | Computers and Games | 20 | 25-03-2008 05:17 AM |