Question

write a java program to find the sum of natural numbers from 1 to 1000 inclusive (using for loop)

sample output:

sum=500500

Answer #1

The program find the sum of natural number from 1 to 1000:

Code:

public class SumNatural {

public static void main(String[] args) {

int num = 1000, sum = 0;

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

{

// sum = sum + i;

sum += i;

}

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

}

}

-----------------------------------------------------------------

The code finds out the sum of the natural numbers from 1 to 1000

Output is : 500500

---------------------------------------------------------Please Upvote--------------------------------------------------------------------------

Write a python program to find the sum of the first n natural
numbers, where the value of n is provided by the user. What is the
sum of the first 200 numbers?
Write a program that finds the average of a series of numbers
entered by the user. As in the previous problem, the program will
first ask the user how many numbers there are. Note: the average
should always be a float. What is the average of 10.2,...

Step 1: Write a Java program that finds the sum of 10 numbers
entered by the user.
Step 2: Modify the previous program so that it asks the user how
many numbers they have, inputs that many numbers, and finally
outputs the average of their numbers. The messages to the user
should be clear throughout.

Write a Java program that gets a 4x4 array of numbers and that calculates the sum and average of numbers on the main diagonal, ie the diagonal that goes from the left corner down to the right corner.
Examples of resulting programs are:
Enter a 4x4 matrix row by row:
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
The sum of numbers in the diagonal is: 16
The average of numbers in...

Using for loops:
- write a Java program that adds numbers between 1 to 100 and
prints the result.
- write a Java program that adds odd numbers between 1 to 100
and prints the result
- write a Java program that averages even numbers between 5 to
30 and prints the result

Write a program with while loop that prints all numbers
between 5 and 100 (inclusive) that are divisible by 5.

Python code
Write a complete program with for loop which calculates the sum
of the numbers from 1 to 100

write a java code.
Write a program using loops to compute the sum of the 30 terms
of the series below.
91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 +
11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . .
Output:
Term Ratio Sum
1 13 13
2 18.4 31.4
etc etc

Write a Python function that prints the numbers
from 100 to 200 inclusive using a while
loop. Thank you.

Write a Python function that prints the numbers
from 100 to 200 inclusive using a while
loop. Thank you.

Step 2 Exercise - Using while loop:
Write a Java program (using while loop) to
display 5 lines of smiley faces. The following would be the output
of your program:
Note: Sample program is in the "Important Documents", Module 6
folder)
Hello:
Bye!

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 12 minutes ago

asked 12 minutes ago

asked 14 minutes ago

asked 16 minutes ago

asked 35 minutes ago

asked 42 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago