Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5.  
  6. struct Material
  7. {
  8.     double Mass;
  9.     double Volume;
  10.     double p;
  11. };
  12.  
  13. int main()
  14. {
  15.  
  16.     int n;
  17.     printf("Enter razmer\n");
  18.     scanf_s("%d",&n);
  19.     struct Material* k = (struct Material*)malloc(sizeof(struct Material) * n);
  20.  
  21.     for (int i = 0; i<n; i++)
  22.     {
  23.         while (k[i].Mass<0)
  24.         {
  25.             printf("Enter mass %d\n", i);
  26.             scanf_s("%lf", &k[i].Mass);
  27.         }
  28.         while (k[i].Volume<0)
  29.         {
  30.             printf("Enter volume %d\n", i);
  31.             scanf_s("%lf", &k[i].Volume);
  32.         }
  33.         k[i].p = k[i].Mass / k[i].Volume;
  34.     }
  35.  
  36.     double min = k[0].p;
  37.     for (int i = 0; i<n; i++)
  38.     {
  39.         printf("p %d=%lf\n", i, k[i].p);
  40.         if (k[i].p<min)
  41.         {
  42.             min = k[i].p;
  43.         }
  44.     }
  45.     printf("Min p=%lf", min);
  46.     _getch();
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement