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"
- #define N 5
- void populateArrayFromFile(FILE *myFile, const int *numberArray, int i);
- /* Given a text file, the elements of which are real numbers a1, a2, a3, ..., an. Create a file
- real numbers b1, b2, b3, ..., bn, where*/
- int fileIsOpen(FILE *file, char fileName[]) {
- if (file == NULL) {
- printf("%s is not open", fileName);
- return -1;
- }
- }
- int main() {
- int size = N;
- FILE *myFile;
- myFile = fopen(INPUT, "r");
- //if(fileIsOpen(myFile, INPUT) == -1) return -1;
- //read file into array
- int inputArray[size];
- for (int i = 0; i < size; i++) {
- fscanf(myFile, "%d", &inputArray[i]);
- }
- FILE *o = fopen(OUTPUT, "w");
- //if(fileIsOpen(myFile, INPUT) == -1) return -2;
- double outputArray[size];
- printf("\n");
- float f;
- for (int i = 0, t = 0; i < sizeof(inputArray) / sizeof(inputArray[0]); ++i, t = 0) {
- for (int j = 0; j < i + 1; ++j) {
- t += inputArray[j];
- }
- f = (float) inputArray[i] / (float) (1 + t * t);
- printf("%lf\n", (double) f);
- outputArray[i] = f;
- fprintf(o, "%.2f ", outputArray[i]);
- }
- fclose(o);
- }
Advertisement
Add Comment
Please, Sign In to add comment