CS13002 Programming and Data Structures

Section 3/C, Spring 2003--2004

Assignment 1 : Solution


The program

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

int main ()
{
   double a, b, c, d, e;
   double AM, GM, HM, SD;

   printf("a = "); scanf("%lf",&a);  /* Echo not shown */
   printf("b = "); scanf("%lf",&b);  /* Echo not shown */
   printf("c = "); scanf("%lf",&c);  /* Echo not shown */
   printf("d = "); scanf("%lf",&d);  /* Echo not shown */
   printf("e = "); scanf("%lf",&e);  /* Echo not shown */

   AM = (a + b + c + d + e) / 5.0;
   GM = pow(a*b*c*d*e,0.2);
   HM = 5.0 / ((1/a)+(1/b)+(1/c)+(1/d)+(1/e));
   SD = sqrt((a*a + b*b + c*c + d*d + e*e)/5 - (AM*AM));

   printf("\n");
   printf("AM = %lf\n", AM);
   printf("GM = %lf\n", GM);
   printf("HM = %lf\n", HM);
   printf("SD = %lf\n", SD);
}

Output

For test input 1

a = 2
b = 29
c = 541
d = 7919
e = 104729

AM = 22644.000000
GM = 482.028272
HM = 9.320238
SD = 41151.947337

For test input 2

a = 148.41315910
b =  54.59815003
c =  20.08553692
d =   7.389056099
e =   2.718281828

AM = 46.640837
GM = 20.085537
HM = 8.649690
SD = 54.029624


Lab home