Advertisement
Soverein

Untitled

Mar 5th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5. FILE* outpos;
  6. FILE* outneg;
  7. FILE* myfile;
  8. double APosNum(float* mas1)
  9. {
  10. int temp = 0;
  11. for (int i = 0; i < 10; i++)
  12. {
  13. if (mas1[i] > 0)
  14. {
  15. temp++;
  16. fprintf(outpos, "%.2f ", mas1[i]);
  17. }
  18. }
  19. return temp;
  20. }
  21. double ANegNum(float* mas1)
  22. {
  23. int temp1 = 0;
  24. for (int i = 0; i < 10; i++)
  25. {
  26. if (mas1[i] < 0)
  27. {
  28. temp1++;
  29. fprintf(outneg, "%.2f ", mas1[i]);
  30. }
  31. }
  32. return temp1;
  33. }
  34. void RANDOM()
  35. {
  36. myfile = fopen("./file.txt", "w");
  37. float NUM;
  38. for (int i = 0; i < 10; i++)
  39. {
  40. NUM = (rand() % 210 - 100) / 10.0;
  41. fprintf(myfile, "%.2f ", NUM);
  42. }
  43. fclose(myfile);
  44. }
  45. int main()
  46. {
  47. RANDOM();
  48. const int n = 10;
  49. float mas1[n];
  50. outpos = fopen("./outpos.txt", "w");
  51. outneg = fopen("./outneg.txt", "w");
  52. myfile = fopen("./file.txt", "r");
  53. if (!myfile)
  54. {
  55. printf("not found");
  56. return 0;
  57. }
  58. int i=0;
  59. while (!feof(myfile))
  60. {
  61. fscanf(myfile,"%f", &mas1[i]);
  62. i++;
  63. }
  64. double temp, temp1;
  65. temp = APosNum(mas1);
  66. temp1 = ANegNum(mas1);
  67. fprintf(myfile, "\nThe amount of the pos num is : %f\n", temp);
  68. fprintf(myfile, "\nThe amount of the neg num is : %f\n", temp1);
  69. fclose(myfile);
  70. fclose(outpos);
  71. fclose(outneg);
  72. return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement