1
\$\begingroup\$

What are some tips on how to shorten this code even further? The code is meant to compute the parallel resistance of an electric circuit.

Using scanf

float r;main(){float a;scanf("%f",&a);r+=1/a;printf("%f",1/r);main();}

Using command-line arguments

#include<stdlib.h>
float r;main(c,v)char**v;{for(int i=1;i<c;)r+=1/atof(v[i++]);printf("%f",1/r);}

Thanks

\$\endgroup\$
  • 4
    \$\begingroup\$ Your first program doesn't halt. Is it intend behavior? \$\endgroup\$ – tsh Dec 4 '19 at 5:49
  • 3
    \$\begingroup\$ For a tips question, please include an exact description of what the code is required to do, and ideally some test cases. That way we tell what's necessary and what is incidental to your chosen implementation. \$\endgroup\$ – xnor Dec 4 '19 at 7:34
  • \$\begingroup\$ I've marked this as a duplicate because it has almost exactly the same title, and there exists a C answer there \$\endgroup\$ – Jo King Dec 4 '19 at 9:29

Browse other questions tagged or ask your own question.