ANSWER USING JAVA CODE
(1)The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
(2) Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.
What is the total of all the name scores in the file?
(3) A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
(4)If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.
(5)The following iterative sequence is defined for the set of positive integers:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.
Program:
import java.io.*;
class Main {
static int squaresum(int n) // called function
{
int square_sum = 0; // variable declaration
for (int i = 1; i <= n; i++) // Loop runs from 1 through n
square_sum += (i * i); // calculate square sum
return square_sum; // return square sum
}
static int sumsquare(int n) // called function
{
int sum_square = 0; // variable declaration
for (int i = 1; i <= n; i++) // Loop runs from 1 through n
sum_square += i; // calculate sum of n numbers
sum_square*=sum_square; // calculate sum square
return sum_square; // return sum square
}
public static void main(String args[]) throws IOException
{
int n = 100,a,b,difference; // variable declaration
a=squaresum(n); // calling function
b=sumsquare(n); // calling function
difference=b-a; // Find difference between the sum of the squares of the first one hundred natural numbers and the square of the sum
System.out.println("\nSum of the squares of the first 100 natural numbers "+a);
System.out.println("\nSquare of the sum of first 100 natural numbers "+a);
System.out.println("\nDifference between the sum of the squares of the first one hundred natural numbers and the square of the sum is "+difference);
}
}
Output:
According to HomeworkLib guidelines i have to solve first question only. Please do next post for remaining answers.
ANSWER USING JAVA CODE (1)The sum of the squares of the first ten natural numbers is,...
8.20 Question. Which natural mumbers can be written as the sum of two squares of natural raumbers? State and prove the mast general theorem possible about which natural numbers can be written as the sum of two suares of nutural numbers, and prove it. We give the most gencral result next. 8.21 Theorem. A natural number n can be written as a sum of two squares of natural mumbers if and only if every prime congruent to 3 modulo 4...
Write a C++ code to make a simple program that imports the input file in and gets the results as specified Please follow the instructions and paste the code below as the answer with a screenshot of the output to prove it worked. Input file -> https://www.dropbox.com/s/444jofkchu6ylwr/names.txt?dl=0 Scoring Names You will be using the provided names.txt file, text file containing over five-thousand first names, and you will calculate a score for each name. Begin by reading the names from the...
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that...
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.
c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...
1. A flowchart is designed to calculate the sum of the first 33 natural numbers. What type of Flow Chart structure this design is? Explain your answer
Write C++ programs that create TEN(10) different N*N magic squares. A square matrix is the arrangement of the numbers 1, 2, ., N2, in which the sum of rows, columns, and diagonals are the same. The users (i.e., TAs) will specify the size of the square matrix: N. The value N must be an odd number between 3 and 15. Example Run For example, you program is expected to run as the following way. NOTE: We only list 5 magic...
1. (a) (i) How many different six-digit natural numbers may be formed from the digits 2, 3, 4, 5, 7 and 9 if digits may not be repeated? (ii) How many of the numbers so formed are even? (iii) How many of the numbers formed are divisible by 3? (iv) How many of the numbers formed are less than 700,000? (b) JACK MURPHY’s seven character password consists of four let- ters chosen from the ten letters in his name (all...
C++ Magic Squares. An n x n matrix that is filled with the numbers 1,2,3,…,n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. The following algorithm will construct magic n x n squares; it only works if n is odd: Place 1 in the middle of the bottom row. After k has been placed in the (i,j) square, place k+1 into the square...
Question 2: (25marks) By definition, the first and second of the modified-Fibonacci numbers are 1 and 2 (e.g. h(0)=1 and h(1)-2), and each subsequent number is the sum of the previous two. a. Write the closed form of the causal Fibonacci function h(n)? b. Write ten Fibonacci number, h(n) for n=0, 1, ,9 described by the above definition? c. Calculate the 4-FFT of the sequence in (b). d. Finally, compute the 4-point IDFT of the result and verify that you...