0% found this document useful (0 votes)
0 views7 pages

Algorithms Concepts Assignment

The document presents algorithms for calculating the sum and average of an array of floating-point numbers, including pseudocode, flow charts, and Java code implementations. The first algorithm sums the elements of the array, while the second calculates the average by dividing the sum by the number of elements. Both algorithms are demonstrated with example arrays and corresponding Java methods.

Uploaded by

charles mutisya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views7 pages

Algorithms Concepts Assignment

The document presents algorithms for calculating the sum and average of an array of floating-point numbers, including pseudocode, flow charts, and Java code implementations. The first algorithm sums the elements of the array, while the second calculates the average by dividing the sum by the number of elements. Both algorithms are demonstrated with example arrays and corresponding Java methods.

Uploaded by

charles mutisya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1

Algorithms Concepts Assignment

Name

Institution

Course

Professor

Date
2

Algorithms Concepts Assignment

1. Algorithm to Return the Sum of an Array of Floating-Point Numbers

I. Pseudocode

Algorithm Sum(arr: array of float) -> float

sum ← 0.0

for each num in arr do

sum ← sum + num

end for

return sum

End Algorithm

II. Flow chart


3

III. JAVA Code

public class ArrayNumbers {

// Method to calculate the sum of floating-point numbers in an array

public static double calculateSum(double[] arr) {


4

double sum = 0.0;

for (double num : arr) {

sum += num;

return sum;

public static void main(String[] args) {

double[] numbers = {1.1, 2.0, 4.2}; // Example array

double sum = calculateSum(numbers);

System.out.println("Sum: " + sum);

2. Algorithm to Return the Average of an Array of Floating-Point Numbers

i. Pseudocode:

Algorithm CalculateAvg(arr: array of float) -> float

sum ← 0.0

for each num in arr do

sum ← sum + num

end for

average ← sum / length(arr)


5

return average

End Algorithm

ii. Flow chart


6
7

iii. JAVA Code

public class Array {

// Method to calculate the average of floating-point numbers in an array

public static double calculateAvg(double[] arr) {

double sum = 0.0;

for (double num : arr) {

sum += num;

return sum / arr.length; // Dividing sum by the number of elements in the array

public static void main(String[] args) {

double[] numbers = {1.2, 2.3, 3.2}; // Example array

double average = calculateAvg(numbers);

System.out.println("Average: " + average);

You might also like