On a slightly different problem, I would like some assistance on how i would code the following programs.
I want to develope a programe that reads a series of characters from a string stored in a text file. The characters are numbers in the text file. Then I need to compute a sum from these numbers. My program should read lines of text from a standard input. Each line will contain a single positive integer.
I have been given the following code to start with.
Given a positive integer, find the sum of its constituent digits.Code:#include<stdio.h> #include<stdlib.h> int main() { constant size_t maxLineLen = 1024 ; char line[ maxLineLen]; while(fgets(line, maxLineLen, stdin) != NULL) { printf("%s", line); } }
My mindmap for the sum value, if you forgive the term, is presented below.
1. Read the string from input
2. Convert each of the character in the string into an integer
3. Read each integer into an array, by using a for loop.
4. In the loop assign variable named sum to zero, each iterstion pf the loop will sum the next arrau value to the previous value named sum.
5. Print the sum value
Write a program that finds the greatest difference between integers in a list. The list can contain positive and negative integers
My program should read lines from a standard input. Each line contains a comma seperated list of integers.
For each input list, print to standard output the greatest difference between any two integers in the list. Print each difference on its own line.
Input example 4, -9,-3,0,7,9
1. Repeat steps 1-3 .
2. In the loop calculate the difference between the all other values in the array from the first value.
3. The next iteration will calculate the difference the other values in the array from the second value.
4. Etc.