// Arup Guha
// 11/2/09
// Written in class for COP 3223 Exam 2 Review

#include <stdio.h>

int numDistinct(int values[], int length);
double sumSqrt(int n);

int main() {

    // Set up test for array question.    
    int vals[] = {3,5,7,4,3,4,6,10,4,1,1,1,1,1,1};
    printf("There are %d diff vals.\n", numDistinct(vals, 15));

    // Test sumsqrt.
    printf("sum up to 201 is %lf\n", sumSqrt(100));
    system("PAUSE");
    return 0;
}

int numDistinct(int values[], int length) {

    int freq[11];
    int i;
    // Initialize array, haven't seen any values yet.
    for (i=0; i<11; i++)
        freq[i] = 0;    
        
    // Tally up how many of each number we have.
    for (i=0; i<length; i++) 
        freq[values[i]]++;
        
    // Count a number if we have at least one occurrence of it.
    int distinct = 0;
    for (i=1; i<11; i++)
        if (freq[i] > 0)
            distinct++;
            
    return distinct;    
}

double sumSqrt(int n) {
    
    // Set up our accumulator variable.
    double sum=0;
    int i;

    // Go through each value and add in the appropriate one.
    for (i=0; i<=n; i++)   
        sum = sum + sqrt(2*i+1);
    
    // Return the answer.    
    return sum;
} 
