Advertisement
Archangelpl

Untitled

May 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // ConsoleApplication5.cpp: Określa punkt wejścia dla aplikacji konsoli.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include<stdio.h>
  7. #include <math.h>
  8.  
  9. FILE *fd;
  10.  
  11. double srA(double *d, int n, double e)
  12. {
  13. double tmp;
  14.  
  15. for(int i=0; i < n; i++)
  16. {
  17. if (e <= d[i])
  18. {
  19. tmp = d[i];
  20. d[i] = e;
  21. e = tmp;
  22. }
  23. }
  24.  
  25.  
  26. for (int i = 0; i < n+1 ; i++)
  27. {
  28. printf("%lf ", d[i]);
  29. }
  30. }
  31. int main()
  32. {
  33. double *d,e;
  34. int n;
  35.  
  36. if (!(fd = fopen("dane.txt", "r")))
  37. {
  38. printf("Blad wczytywania danych");
  39. exit(0);
  40. }
  41. fscanf(fd, "%d", &n);
  42. d = malloc(n * sizeof(double));
  43. printf("Tablica: \n");
  44. for (int i = 0; i < n;i++)
  45. {
  46.  
  47. fscanf(fd, "%lf", &d[i]);
  48. printf("%lf ", d[i]);
  49.  
  50. }
  51. printf("\n podaj liczbe ");
  52. scanf("%lf", &e);
  53. printf("\n Po dod: \n");
  54.  
  55.  
  56. srA(d, n,e);
  57.  
  58.  
  59. printf("\n");
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement