How Do I Rewrite This In C Using Functions?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madstyle51
    New Member
    • Oct 2006
    • 3

    How Do I Rewrite This In C Using Functions?

    #include <stdio.h>
    #include <math.h>


    /* Define the variables. */
    int main ()
    {
    int N;
    float Q[5000];
    float max;
    float min;
    float range;
    float average;

    int J;
    float V=0.0, Sq, De;

    /* print program header message. */

    printf("\n\n CSCI 210 -- C Assignment 5\n");
    printf(" *************** *************** \n");
    printf("Reading , Computing, and Printing from an Array.\n\n");

    /* Declare variables for the file and open and scan it. */
    int s;
    FILE * numbers;
    numbers = fopen("asgn5-1.txt","r");
    while (N = (fscanf(numbers ,"%f", &Q[s]) == 1))
    {
    s++;
    }

    /* prints all the values in the array. */
    int k;

    for(k=0; k<s; k++)
    {
    if (k%6 == 0)
    {
    printf("\n %f", Q[k]);
    }
    else
    {
    printf("\t %f", Q[k]);
    }
    }

    /* Calculate the max.*/
    max = Q[0];
    for (k=1; k<s; k++)
    {
    if(Q[k] > max)
    max = Q[k];
    }

    /* calculate the min. */
    int h;
    min = Q[0];
    for (h=1; h<s; h++)
    if(Q[h] < min)
    min = Q[h];

    /* calculate the range. */
    range = max - min;

    /* calculate the average. */
    int sum=0;
    int e;
    for (e=0; e<=s-1; e++)
    sum += Q[e];

    average = sum/s;

    /* calculate the standard deviation. */

    for (J=1;J<s-1;J++)
    {
    Sq =(Q[J] - average) * (Q[J] - average);
    V = V + Sq;
    }

    De = sqrt(V/s);

    /* print all the values.*/
    printf("\n\nCSC I 210 - Assignment 5");
    printf("\n***** *************** *** \n\n");
    printf("Maximum Value: %5.3f \n", max);
    printf("Minimum Value: %5.3f\n", min);
    printf("Range Value: %5.3f\n", range);
    printf("Number of Values: %5d\n", s);
    printf("average : %5.3f\n", average);
    printf("Standar d Deviation: %5.3f\n", De);

    fclose(numbers) ;

    return 0;
    }
  • RADAR
    New Member
    • Oct 2006
    • 21

    #2
    Northern Illinois University student friend I want you if it is appropriate for you send me the exact question then i will try to solve it.If you wolud not try to make it clear to understand what is expected from you under that topic.I do not hide my mail adress:
    tinb_usa@hotmai l.com
    respects...

    Comment

    Working...