Question: C Programming This is the code I have tried so far. #include #include int square(int num) { int i; float f; f=sqrt((double)num); i=f; if(i==f) return

C Programming

C Programming This is the code I have tried so far. #include

This is the code I have tried so far.

#include #include

int square(int num) {

int i; float f; f=sqrt((double)num); i=f; if(i==f) return 1; else return 0; }

int main() { FILE* file; int e = 0; int g; int sum; file = fopen("testdata.in", "r"); if(file == NULL) { printf("Failed to open file. "); return 1; } fscanf(file, "%d", &e); while(1) { int k = sqrt(e); g++; if(k == 1) { e *=-1; } sum = sum + e; fscanf (file, "%d", &e); if(file == NULL) { break; } } printf("Special sum of %d datas is %d", g, sum); }

In this problem, you are told to calculate the sum of all integers in "testdata.in" file, but you should take all the squared number as a negative in the sum. For example, the sum of "1 2 3" is equal to-1+2+34 Format Input The input will consist of a line contains a lot of numbers in testdata.in file. Please read all the numbers inside this file as the data. Format Output Output "Special sum of X datas is Y." with N as the number of data and Y as the sum of the data with the specified rules. Constraints 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!