Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<stdlib.h>
- using namespace std;
- FILE* outpos;
- FILE* outneg;
- FILE* myfile;
- double APosNum(float* mas1)
- {
- int temp = 0;
- for (int i = 0; i < 10; i++)
- {
- if (mas1[i] > 0)
- {
- temp++;
- fprintf(outpos, "%.2f ", mas1[i]);
- }
- }
- return temp;
- }
- double ANegNum(float* mas1)
- {
- int temp1 = 0;
- for (int i = 0; i < 10; i++)
- {
- if (mas1[i] < 0)
- {
- temp1++;
- fprintf(outneg, "%.2f ", mas1[i]);
- }
- }
- return temp1;
- }
- void RANDOM()
- {
- myfile = fopen("./file.txt", "w");
- float NUM;
- for (int i = 0; i < 10; i++)
- {
- NUM = (rand() % 210 - 100) / 10.0;
- fprintf(myfile, "%.2f ", NUM);
- }
- fclose(myfile);
- }
- int main()
- {
- RANDOM();
- const int n = 10;
- float mas1[n];
- outpos = fopen("./outpos.txt", "w");
- outneg = fopen("./outneg.txt", "w");
- myfile = fopen("./file.txt", "r");
- if (!myfile)
- {
- printf("not found");
- return 0;
- }
- int i=0;
- while (!feof(myfile))
- {
- fscanf(myfile,"%f", &mas1[i]);
- i++;
- }
- double temp, temp1;
- temp = APosNum(mas1);
- temp1 = ANegNum(mas1);
- fprintf(myfile, "\nThe amount of the pos num is : %f\n", temp);
- fprintf(myfile, "\nThe amount of the neg num is : %f\n", temp1);
- fclose(myfile);
- fclose(outpos);
- fclose(outneg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement