Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define INPUT "..\\tess.txt"
- #define OUTPUT "output.txt"
- void populateArrayFromFile(FILE *myFile, const int *numberArray, int i);
- /* Дано текстовий файл, елементами якого є дійсні числа a1, a2, a3, ..., an. Створити файл
- дійсних чисел b1, b2, b3,..., bn, де*/
- int fileIsOpen(FILE *file, char fileName[]) {
- if (file == NULL) {
- printf("%s is not open", fileName);
- return -1;
- }
- }
- int findSize() {
- FILE *myFile;
- myFile = fopen(INPUT, "r");
- int size = 0;
- int k = 0;
- while (!feof(myFile)) {
- size++;
- fscanf(myFile, "%d", k);
- }
- fclose(myFile);
- return size;
- }
- int main() {
- int size = 5;
- FILE *myFile;
- myFile = fopen(INPUT, "r");
- //read file into array
- int inputArray[size];
- for (int i = 0; i < size; i++) {
- fscanf(myFile, "%d", &inputArray[i]);
- }
- for (int i = 0; i < size; i++) {
- printf("%d\n", inputArray[i]);
- }
- FILE *o = fopen("output.txt", "w");
- double outputArray[size];
- printf("\n");
- for (int i = 0; i < sizeof(inputArray) / sizeof(inputArray[0]); ++i) {
- int t = 0;
- for (int j = 0; j < i+1; ++j) {
- t += inputArray[j];
- }
- printf("j[%d]: %d\n", i, t);
- float d = (float)inputArray[i]/(float)(1+t*t);
- printf("%lf\n", (double )d);
- outputArray[i] = d;
- fprintf(o, "%.2f ", outputArray[i]);
- }
- fclose(o);
- }
Advertisement
Add Comment
Please, Sign In to add comment