Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
This is the code I have tried so far.
#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 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started