Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

What is a deferred annuity? Discuss.

Answered: 1 week ago

Question

6. What data will she need?

Answered: 1 week ago

Question

1. How did you go about making your selection?

Answered: 1 week ago