Question

In: Computer Science

Write an algorithm (flowchart) for the following problems: Take ten different numbers as input and display...

Write an algorithm (flowchart) for the following problems:
Take ten different numbers as input and display the sum of there squares (SS).
Example: let the inputs are: 3, 0, -1, 0, 9, -5, 6, 0, 2, 1 then 157 is displayed, because: SS=32+02+(-1)2+02+92+(-5)2+62+02+22+12=157

Solutions

Expert Solution

Answer : Algorithm

Step 1:Take 2 integers i, and sum. i for loop counter variable and sum for storing the sum of squares of all 10 integers.initially initialize the sum to 0

Step 2: Take input of 10 numbers and store them in an array a[10];

Step 3: For each elements in array perform following:

sum=sum+ a[i]*a[i];// where a[i] is the ith element in the array

Step 4: Print the value of sum as the sum of squares of 10 entered integers.

A C program for the above algorithm is:

#include<stdio.h>

main()

{

    int n,i,sum, a[10];

    i=1,sum=0;

  while(i<=n)

{ scanf(%d,&a[i]);

}
   

    while(i<=10)

    {

        sum=sum+i*i;

        ++i;

    }

    printf("Sum of squares of numbers from 1 to n is :%d ",sum);

}


Related Solutions

Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
I have to write an initial algorithm and a refined algorithm for the following problem: Display...
I have to write an initial algorithm and a refined algorithm for the following problem: Display the square of numbers from 0 to some user inputted value. For example if the user enters 3 then the program will need to display the square of 0, 1, 2 and 3. Must use a counter loop. Must use 2 methods. One method that gets the number from the user and returns it. A second method is passed that number as a parameter...
Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart...
Develop an Algorithm and java program using Design Recipe for the following problems. Draw a flowchart to compute the largest and smallest of 4 numbers : Write a Java Program for the above flowchart, use methods(functions), and nested if-else statements. Take input from the user using the Scanner object. Use separate methods to compute the Largest and Smallest of the numbers. Method 1 Name: findLargest(param 1, param 2, param 3, param 4) Method 2 Name: findSmallest(param 1, param 2, param...
Input 10 integers and display the following: a. the sum of even numbers. b. the sum...
Input 10 integers and display the following: a. the sum of even numbers. b. the sum of odd numbers. c. the largest integer d. the smallest integer e. the total count of even numbers f. the total count of odd numbers. Using C++ program with for loop..
Make an algorithm in the form of a sentence and flowchart from the following cases: Algorithm...
Make an algorithm in the form of a sentence and flowchart from the following cases: Algorithm for calculating the amount of net salary if known: the amount of base salary, allowances, melting money, taxes, and credit deductions.
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
A student is going to take an survey of ten problems. Suppose among the problems that...
A student is going to take an survey of ten problems. Suppose among the problems that may appear in the exam, the student can solve 20% of them correctly, and 60% partially correctly. If you know that the student can solve exactly three problems in the survey correctly, what is the expected number of problems that he or she can solve partially correctly ? Find the conditional probability that the student can solve exactly three problems partially correctly given that...
Write out the formulas, with the numbers filled in, to solve the following problems. For (a)...
Write out the formulas, with the numbers filled in, to solve the following problems. For (a) and (b), the market interest rate is 6.20%. You do not have to do the actual calculations for (a) through (c), but (d) requires a calculation. (a) Find the price of a 10-year bond (par = $1,000) with an annual coupon of 5.80%. Is this bond at a premium or discount? Explain briefly. (6 points). (b) Find the price of a 10-year bond (par...
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT