Question

In: Computer Science

1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any...

1. Write pseudocode for the algorithm using iteration (looping).

Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n. For example given 3 the algorithm will print 14 (because 1 + 4 + 9 =14) You can use multiplication denoted as * in your solution and you do not have to define it (For example. 3*3=9) For example if n is 6 it will print: The sum of squares from 1 to 6 = 91 Again, to get marks, the algorithm needs to work for any n given.

Solutions

Expert Solution

Pseudocode

Function SumOFSquare (n)

1. Declare integers variables n, sum, iteration variable(i)

2. IF n larger than 0:

FOR ( i equals to 1 [initialization statement]

i less than or equal to n    [ condition statement]

incrementation of i)    [increment statement]

sum equals to sum added with ( i*i)

3. ELSE

PRINT "Input number is non negative integer"

4. RETURN sum

*Providing a C code for the above program for reference

#include <stdio.h>

int main()
{
   int sum=0, n, i;
   printf("Input number n:");
   scanf("%d", &n);
   if (n>0)
   {
       for (i=1;i<=n;i++)
       {
           sum=sum+(i*i);
       }
       printf("sum=%d", sum);
   }
   else
       printf("Input number is non positive integer!!");
}


Related Solutions

Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm and quick union algorithm
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the...
Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the integers not common to both arrays. When writing pseudocode, consider that no implementation for data structures or algorithms exist. b) Implement your algorithm in Modern C++
1. Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1,...
1. Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1, 0, 2, 1, 5, 0, 4                                                                     No code or programs, please. Manually solve the problem, please. Thanks
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
1) Using algorithm or pseudocode, describe the implementation of the server side of a public chatroom...
1) Using algorithm or pseudocode, describe the implementation of the server side of a public chatroom application with the following specification: Any client that wishes to join the chatroom, must send the message “Hello” to the server’s IP address at port 2020. After sending the “Hello” message, the client is admitted into the chatroom. While in the chatroom, any message sent by any client must be received by all other clients. Finally, when a client decides to leave the chatroom,...
Sort the given keys using Counting sort algorithm. Also write the algorithm. 5, 2, 3, 1,...
Sort the given keys using Counting sort algorithm. Also write the algorithm. 5, 2, 3, 1, 0, 2, 1, 5, 0  
PSUEDOCODE: Using whatever looping mechanism makes sense to you, create an algorithm that will display timing...
PSUEDOCODE: Using whatever looping mechanism makes sense to you, create an algorithm that will display timing for a stopwatch. Keep the following in mind: We can assume that you're processing on the world's oldest, slowest computer and that each iteration of a loop takes exactly one/100th of a second The user needs to see fractions of a second all the way to 24 hours - any more and we should really call for medical help... Provide a way for the...
Write a program that implements the A* algorithm to find a path from any two given...
Write a program that implements the A* algorithm to find a path from any two given nodes. You may use any of the following languages: C++, C#, Java, ActionScript. Problem Overview & Algorithm Description In a fully-observable environment where there are both pathable and blocked nodes, an agent must find a good path from their starting node to the goal node. The agent must use the A* algorithm to determine its path. For this program, you must use the Manhattan...
Write a program, using any language you want, and any sorting algorithm discussed in this unit...
Write a program, using any language you want, and any sorting algorithm discussed in this unit to sort the following : 243, 1, 4, 6, 234, 33, 674, 32, 3333 Note: Can you write it in quick sort
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT