LAB 01: Standard Deviation Lab - C Version

  • Lab 01 Report form, .doc

    Objective
    Learning C programming, C array processing. Topics include

    1. Compiling C programs
    2. keyboard I/O:printf() and scanf() (C) cout/cin (C++),
    3. file creation and file i/o: FILE *infile, FILE *outfile, and fopen() (C)
      fscanf() and fprintf() (C)
      ifstream infile() and ofstream outfile() (C++),
    4. Constants: #define MAXVALS 100 (C)
      const int MAXVALS=100; (C++)
    5. static array: int myarray[MAXVALS]: C and C++
    6. "Random" numbers in C and C++

      If you'd like to work with dynamically allocated arrays in C:

    7. dynamic arrays: C:
      int *myarray;
      scanf("%d", &numVals); myarray=(int *)malloc(sizeof(int)*numVals);
      "malloc" stands for "memory allocation"
    8. deletion of dynamic arrays
      delete myarray (C++)
      free(myarray) (C)
    9. dynamic arrays: C++:
      int *myarray;
      cin >> numVals; myarray=new int[numVals];

    Part 1

    1. Download this program to write random numbers to a file: randomNumFile.c, (for C++ see randomNumFile.cpp)
    2. Run the program to create a file of 50 or more random numbers
      -- Look at the contents of each of the number files to verify the programs worked.

    Part 2 - Static arrays (and dynamic allocation if you'd like) in C
    printResults.c - shell file to print your results to a file