Question

the Note that you must display 4.4 Write a program that computes the sum of all the negative integers in a list As input, the

Please show me the source code of this problem with C language (I only learned C before), thank you~

0 0
Add a comment Improve this question Transcribed image text
Answer #1


/*
 *  C Program to sum negative integers from file
 */

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int *ptrNum, N;
  int num, sum = 0, i = 0;

  FILE *fptr = fopen("SUMNEG.DAT", "r");

  fscanf(fptr, "%d", &N);
  ptrNum = (int *) malloc(N * sizeof(int));

  for (i = 0; i < N; i++)
  {
    fscanf(fptr, "%d", &num);
    ptrNum[i] = num;
    
    if (num < 0)
      sum += num;
  }

  fclose(fptr);

  printf("The sum of the negative integer is: \n%d\n", sum);
  printf("The list of integer is: \n");
  for (i = 0; i < N; i++)
  {
    printf("%d\n", ptrNum[i]);
  }
  
  return 0;
}

/*  Program ends here */

imtusharsharma/ Empty Inequal edTruetype C No description share - new repl my repls languages 98 talk notifications imtushars

imtusharsharma/ Empty Inequal edTruetype C No descriphion share - new repl my repls languages 98 talk notifications imtushars

Add a comment
Know the answer?
Add Answer to:
Please show me the source code of this problem with C language (I only learned C...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The problem is in these two pictures, please show me the source code~ 4.2. The binomial theorem can be written as 4.3....

    The problem is in these two pictures, please show me the source code~ 4.2. The binomial theorem can be written as 4.3. W A d SS a'"-2h2 n(n - 1)(n - 2) 2! (a+ b)" = a"+1na-1hn(n-1) 3! Write a program for which a = 1 and 0 < b < 1 that uses the binomial theorem to calculate (a + b)" accurately to eight decimal places. Your pro- gram should also calculate (a + b)" using the pow() function....

  • Can someone please help me with this problem? We are using CodeWarrior to write this program...

    Can someone please help me with this problem? We are using CodeWarrior to write this program in assembly language. The array sample contains eight 8-bit signed binary numbers (integers) as shown below. Write a program which stores the negative numbers in the array nelements, computes the sum of the positive numbens to be stored in the variable psum and stores the number of the positive numbers in the variable pnumber. Note that a zero is ther positive nor negative. Your...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

  • needs to be written in C language. please show that code works in command prompt if...

    needs to be written in C language. please show that code works in command prompt if possible. 4. write program to take two numerical lists of the same length ended by a sen- 4. a tinel value and store the lists in arrays x and y, each of which has 20 elements. Let n be the actual number of data values in each list. Store the product of corresponding elements oflx and in a third a 2. also of size...

  • Please give me that correct code for this by using C++ language. and i hope you...

    Please give me that correct code for this by using C++ language. and i hope you use Visual stduio Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }.  For example, the string  {a(b+ac)d[xy]g} and  kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match...

  • program in C. please paste code, thanks! CS 153 Program 4 - Stirling Approximation (separate compilation)...

    program in C. please paste code, thanks! CS 153 Program 4 - Stirling Approximation (separate compilation) 1. Write a pure function double factoriallint Ni that computes N! N 1023°4 ... N-1)'N Do this the obvious way by initializing a product to one and then multiplying the integers together using a loop. Zero factorial is defined to be one. Now write a pure function double atining in Ni that uses the Stirling approximation to compute: approx[e!) - V22) In this formula,...

  • Please help me with this C++ I would like to create that uses a minimum spanning tree algorithm in C++. I would like the program to graph the edges with weights that are entered and will display the r...

    Please help me with this C++ I would like to create that uses a minimum spanning tree algorithm in C++. I would like the program to graph the edges with weights that are entered and will display the results. The contribution of each line will speak to an undirected edge of an associated weighted chart. The edge will comprise of two unequal non-negative whole numbers in the range 0 to 99 speaking to diagram vertices that the edge interfaces. Each...

  • Please use C programming to write the code to solve the following problem. Also, please use the i...

    Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...

  • Please help me write in C++ language for Xcode. Thank you. In this lab you are...

    Please help me write in C++ language for Xcode. Thank you. In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than...

  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT