Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lyseis: konprou.blogspot.com
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void main()
- {
- /*float temperatures[10];
- float sum=0, avg, furthest;
- int i;
- for(i=0;i<10;i++)
- {
- printf("Give temperature: ");
- scanf("%f", &temperatures[i]);
- sum+=temperatures[i];
- }
- avg=sum/10;
- furthest=temperatures[0];
- for(i=1;i<10;i++)
- {
- if(fabs(temperatures[i]-avg) > fabs(furthest-avg))
- furthest=temperatures[i];
- }
- printf("The temperature that is the furthest one from the avg temperature is %.2f.\n", furthest);
- */
- //2nd one
- int codes[10], i;
- float prices[10];
- float my_max, my_min;
- int index1, index2;
- for(i=0;i<10;i++) // read prices/codes
- {
- printf("Give code and price: ");
- scanf("%d %f", &codes[i], &prices[i]);
- }
- my_max=my_min=prices[0];
- index1=index2=0;
- for(i=1;i<10;i++)
- {
- if(my_max < prices[i])
- {
- my_max=prices[i];
- index1=codes[i];
- }
- if(my_min > prices[i])
- {
- my_min=prices[i];
- index2=codes[i];
- }
- }
- printf("Max price %.2f with code %d, min price %.2f with code %d.\n", my_max, index1, my_min, index2+1);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement