1. Write an algorithm to calculate sum of n numbers (Sum of 1 to n) where n is d
ID: 3910932 • Letter: 1
Question
1. Write an algorithm to calculate sum of n numbers (Sum of 1 to n) where n is defined by the user. a) Using brute force method (loop) b) Using formula (sum n*(n+1)/2) 2. Write an algorithm to calculate gross pay of one or more employees. You algorithm must ask for number of employess and calculate gross pay for each of them. It should also calculate overtime if an employeed worked for more than 40 hours. Over time is calculated as follows: over time (number of hours worked - 40) pay rate 1.5 3. Write an algorithm to calculate exact cube root of a number. a) Use brute force method b) Use an improvement of brute force methodExplanation / Answer
If you post more than 1 question, as per chegg guidelines I have to solve only first question.
Ques 1.
(a)
Function sum(n)
BEGIN
// stores the sum from 1 to n
total = 0
// loop from 1 to n
for I = 1 to n
BEGIN
total = total + i
END
print(sum)
END
(b)
Function sum(n)
BEGIN
// n + 1
// sum = n * ( ---------- )
// 2
total = n * ( n + 1 ) / 2
print(sum)
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.