2
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
4Your first program doesn't halt. Is it intend behavior? – tsh – 2019-12-04T05:49:45.700
3For 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. – xnor – 2019-12-04T07:34:14.987
I've marked this as a duplicate because it has almost exactly the same title, and there exists a
C
answer there – Jo King – 2019-12-04T09:29:04.977