/*Source Code for Wave.c*/ /*absolute value function*/ double absolute_value (x) double x; { if(x<0.0) x = x; return (x); } /*function to get a square root*/ double square_root (x) double x; { double epsilon = 0.000001; double guess = 1.0; if (x<0) { printf("Negative argument to square root function\n"); return(1.0); } while (absolute_value(guess*guessx) >= epsilon) guess = (x/guess+guess)/2.0; /* printf("Square Root = %f \n", guess); */ return (guess); } /*Program to convert accelerating voltage to wavelength*/ main(narg,listarg) int narg; char *listarg[]; { double kilovoltage, voltage, numerator = 12.26; double denompart1 = 1.0, denompart2= 9.788e07; double wavelength, thousand = 1000.0, denomtotal; if(narg==1) { printf("enter accelerating voltage in kV \n"); scanf("%lf", &kilovoltage); } else { sscanf(listarg[1],"%lf",&kilovoltage); } voltage = kilovoltage * thousand; denomtotal = square_root(voltage * (denompart1 + denompart2 * voltage)); wavelength = numerator / denomtotal; printf("wavelength in Angstroms = %0.7f\n", wavelength); }
These pages created by: The University of Michigan Electron Microbeam Analysis Laboratory & The Department of Materials Science & Engineering  


This page has been visited  times. 