Skip to content
Snippets Groups Projects
einstein.c 603 B
Newer Older
Bruce Cowan's avatar
Bruce Cowan committed
/*
 * SPDX-FileCopyrightText: 2018 Bruce Cowan <bruce@bcowan.me.uk>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
Bruce Cowan's avatar
Bruce Cowan committed
 */

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)
{
Bruce Cowan's avatar
Bruce Cowan committed
    double m;
Bruce Cowan's avatar
Bruce Cowan committed
    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");
Bruce Cowan's avatar
Bruce Cowan committed
            return EXIT_FAILURE;
Bruce Cowan's avatar
Bruce Cowan committed
        }
    }
Bruce Cowan's avatar
Bruce Cowan committed
    double e = m * C2;
    printf ("E = %#.3G J\n", e);
Bruce Cowan's avatar
Bruce Cowan committed
    return 0;