Skip to content

Commit 4030170

Browse files
author
Robert
committed
add Joule calculator
1 parent c488993 commit 4030170

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

joules.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Compile with gcc -Wall -o joules joules.c -lm
2+
The Lightning Stalker 2023/12/14 */
3+
4+
#include <math.h>
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <locale.h>
8+
9+
int main (int argc, char **argv)
10+
{
11+
unsetenv ("LC_ALL");
12+
setlocale (LC_NUMERIC, ""); // This should give us digit grouping
13+
14+
if (argc == 3)
15+
{
16+
printf ("%'.3f\n", 0.0000005 * atof(argv[1]) * \
17+
powf(atof(argv[2]), 2));
18+
return (0);
19+
}
20+
else
21+
{
22+
puts ("joules is a simple capacitor joule calculator.");
23+
puts ("output is stored energy in joules\n");
24+
puts ("Usage: joules microfarads volts");
25+
puts ("Example: joules 33 330");
26+
puts ("Output should be: 1.797");
27+
return (1);
28+
}
29+
}

0 commit comments

Comments
 (0)