Skip to content
Snippets Groups Projects
einstein.c 415 B
Newer Older
Bruce Cowan's avatar
Bruce Cowan committed
#include <stdio.h>
#include <stdlib.h>

#define C 299792458
#define C2 (C)*(C)

int
main (int argc, char **argv)
{
	double m;

	if (argc != 2)
	{
		printf ("Input the mass in kg: ");
		scanf ("%lf", &m);
	}
	else
	{
		if (sscanf (argv[1], "%lf", &m) != 1)
		{
  			fprintf (stderr, "Couldn't parse number\n");
            return EXIT_FAILURE;
		}
	}

	double e = m * C2;
	printf ("E = %#.3G J\n", e);

	return 0;
}