Advertisement
Guest User

Faye vap 5

a guest
Nov 27th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. // lyseis: konprou.blogspot.com
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. void main()
  7. {
  8.     /*float temperatures[10];
  9.     float  sum=0, avg, furthest;
  10.     int i;
  11.  
  12.     for(i=0;i<10;i++)
  13.     {
  14.        printf("Give temperature: ");
  15.        scanf("%f", &temperatures[i]);
  16.        sum+=temperatures[i];
  17.     }
  18.     avg=sum/10;
  19.  
  20.     furthest=temperatures[0];
  21.     for(i=1;i<10;i++)
  22.     {
  23.        if(fabs(temperatures[i]-avg) > fabs(furthest-avg))
  24.            furthest=temperatures[i];
  25.     }
  26.     printf("The temperature that is the furthest one from the avg temperature is %.2f.\n", furthest);
  27.     */
  28.  
  29.     //2nd one
  30.     int codes[10], i;
  31.     float prices[10];
  32.     float my_max, my_min;
  33.     int index1, index2;
  34.  
  35.     for(i=0;i<10;i++) // read prices/codes
  36.     {
  37.        printf("Give code and price: ");
  38.        scanf("%d %f", &codes[i], &prices[i]);
  39.     }
  40.  
  41.     my_max=my_min=prices[0];
  42.     index1=index2=0;
  43.     for(i=1;i<10;i++)
  44.     {
  45.         if(my_max < prices[i])
  46.         {
  47.             my_max=prices[i];
  48.             index1=codes[i];
  49.         }
  50.  
  51.         if(my_min > prices[i])
  52.         {
  53.             my_min=prices[i];
  54.             index2=codes[i];
  55.         }
  56.     }
  57.  
  58.     printf("Max price %.2f with code %d, min price %.2f with code %d.\n", my_max, index1, my_min, index2+1);
  59.     system("pause");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement