define SIZE 5 int mainvoid int firstSIZE secondSIZE diffSIZE i printfEnter d

Define size 5 int mainvoid int firstsize secondsize

This preview shows page 12 - 14 out of 14 pages.

#define SIZE 5 int main(void) { int first[SIZE], second[SIZE], diff[SIZE], i; printf("Enter %d data items for first array : ", SIZE); for(i=0;i<SIZE; i++) // input first array scanf("%d",&first[i]); printf("Enter %d data items for second array : ", SIZE); for(i=0;i<SIZE; i++) // input second array scanf("%d",&second[i]); for(i=0;i<SIZE; i++) // compute the differences diff[i]= second[i] - first[i]; printf("\n\nOutput of the arrays : \n"); for(i=0;i<SIZE; i++) // output the arrays printf("%5d %5d %5d\n", first[i], second[i], diff[i]); system("pause"); return 0; }
Image of page 12
13 Example 3 /* Computes the mean and standard deviation of an array of data and displays the difference between each value and the mean. */ #include <stdio.h> #include <math.h> #define SIZE 8 /* maximum number of items in list of data */ int main(void) { double x[SIZE], mean, st_dev, sum, sum_sqr; int i; /* Gets the data */ printf("Enter %d numbers separated by blanks\n> ", SIZE); for (i = 0; i < SIZE; ++i) scanf("%lf", &x[i]); /* Computes the sum and the sum of the squares of all data */ sum = 0; sum_sqr = 0; for (i = 0; i < SIZE; ++i) { sum += x[i]; sum_sqr += x[i] * x[i]; }
Image of page 13
14 Example 3… /* Computes and prints the mean and standard deviation */ mean = sum / SIZE; st_dev = sqrt(sum_sqr / SIZE - mean * mean); printf("The mean is %.2f.\n", mean); printf("The standard deviation is %.2f.\n", st_dev); /* Displays the difference between each item and the mean */ printf("\nTable of differences between data values and mean\n"); printf("Index Item Difference\n"); for (i = 0; i < SIZE; ++i) printf("%3d%4c%9.2f%5c%9.2f\n", i, ' ', x[i], ' ', x[i] - mean); system("pause"); return (0); }
Image of page 14

You've reached the end of your free preview.

Want to read all 14 pages?

  • Spring '10
  • baleh
  • Array, #include, #define, Array Array Initialization

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes