To complete the program, you need to define the FindSum function that calculates the sum of positive numbers that a user inputs. Here is how you can do it:
#include <stdio.h>
int FindSum(int n) { int i, number, sum = 0; // Loop through each number the user inputs for(i = 0; i < n; i++) { printf("Enter number %d: ", i+1); scanf("%d", &number); // Add to sum if the number is positive if(number > 0) { sum += number; } } return sum; }
How it Works
Prompt for Numbers: The function FindSum takes the integer n as an argument, indicating how many numbers the user will enter.
Input Loop: We loop n times, each time prompting the user to enter a number.
Check for Positivity: Inside the loop, after reading each number, we check if it is positive.
Calculate Sum: If a number is positive, we add it to the sum. If it's not positive, we ignore it.
Return the Sum: After all numbers are processed, the function returns the calculated sum of all positive numbers entered by the user.
This code will work to read the given sequence of numbers input by the user and will compute the sum of only the positive ones, demonstrating basic skills in using conditionals and loops in C programming.