Question

1.Create the algorithm for the following problem. Considering the first 20 natural numbers, calculate the sum of these numbers, the sum of their squares, and the sum of their cubes. Display all the sums at the end of the solution. Post your response as flowchart or pseudocode.

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

public class Main f public static void main(String args 1) int sum-e, square_sum-e,cube_sum-0; int t1,t2; for(int i-1;i<-20;i++) sum += 1; square_sumt1; cubesum += t2; - System.out.println(The sum +sum); System.out.println(The sum of squares: +square_sum); System.out.println(The sum of cubes : +cube_sum); Sample output: The sum 210 The sum of squares: 2870 The sum of cubes :44100

code:

{

int sum=0,square_sum=0,cube_sum=0;

int t1,t2;

for(int i=1;i<=20;i++)

{

sum += i;

t1 = i*i;

square_sum += t1;

t2 = t1*i;

cube_sum += t2;

}

}

Add a comment
Know the answer?
Add Answer to:
1. Create the algorithm for the following problem. Considering the first 20 natural numbers, calculate the...
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
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