LAB 01: Standard Deviation Lab - C Version
Lab 01 Report form,
.doc
Objective
Learning C programming, C array processing. Topics include
- Compiling
C programs
- keyboard I/O:printf() and scanf() (C)
cout/cin
(C++),
- file creation and file i/o: FILE
*infile, FILE *outfile, and fopen() (C)
fscanf() and fprintf() (C)
ifstream
infile() and ofstream outfile() (C++),
- Constants: #define MAXVALS 100 (C)
const int MAXVALS=100; (C++)
- static array: int myarray[MAXVALS]:
C
and
C++
- "Random" numbers in
C
and
C++
If you'd like to work with dynamically allocated arrays in C:
- dynamic arrays:
C:
int *myarray;
scanf("%d", &numVals); myarray=(int *)malloc(sizeof(int)*numVals);
"malloc" stands for "memory allocation"
- deletion of dynamic arrays
delete myarray (C++)
free(myarray) (C)
- dynamic arrays:
C++:
int *myarray;
cin >> numVals; myarray=new int[numVals];
Part 1
- Download this program to write random numbers to a file:
randomNumFile.c,
(for C++ see
randomNumFile.cpp)
- 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
- Write a C program to put 1000 random numbers in an array. (See if the static array can hold 10000 or more values without a segmentation memory fault)
- Print the array of values
- Find the highest and lowest values
- Find the average value
- Find the standard deviation
- Sort the numbers