Source Code for Wave.c by John F. Mansfield

This is the first and, so far, only c program I have ever written!

		/*Source Code for Wave.c*/
        /*absolute value function*/

        double absolute_value (x)
        double x;
                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");
                while (absolute_value(guess*guess-x) >= epsilon)
                guess = (x/guess+guess)/2.0;
        /*      printf("Square Root = %f \n", guess);  */
                return (guess);
        /*Program to convert accelerating voltage to wavelength*/

        int narg;
        char *listarg[];

                double kilovoltage, voltage, numerator = 12.26;
                double denompart1 = 1.0, denompart2= 9.788e-07;
                double wavelength, thousand = 1000.0, denomtotal;

        printf("enter accelerating voltage in kV \n");
        scanf("%lf", &kilovoltage);
        voltage = kilovoltage * thousand;

        denomtotal = square_root(voltage * (denompart1 + denompart2 *

        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
Comments, criticisms, compliments,
etc. may be directed to:

John F. Mansfield (

This Page last updated:
Monday, 17th March, 1997
This page has been visited times.