answersLogoWhite

0


Best Answer

Since 7 and 9 are relatively prime, any number that is a multiple of both is a multiple of 7 x 9 = 63. There are 9 multiples of 63 less than or equal to 600, so this can be computed directly using Sum = 63(1 + 2 + ... + 9) which simplifies to Sum = 63 x 9 x (1 + 9)/2 from the formula for arithmetic series.

Most programming languages have a built-in function which returns the quotient and the remainder when dividing integers, or you can write your own. So to generalize, denote 600 by max, 7 by a, and 9 by b. Input those values first. Suppose quotient returns the quotient of an integer division.

begin

N <- quotient(max, lcm(a,b)) (* N is the number of multiples of both a and b <= max *)

sum <- lcm(a,b) * N * (1 + N)/2 (* Use the formula *)

end

This is the most efficient solution. There are other solutions that don't assume an understanding of arithmetic series. Specifically, you could write:

begin

i <- 1; sum <- 0 (* Initialize counter to 1 and sum to 0 *)

While i <= max/lcm(a,b) do

sum <- sum + i * lcm(a,b)

i++;

od

end

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a complete pseudo-code of a program which adds all numbers that are multiples of both 7 and 9 up to 600.?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Develop an algorithm to display all prime numbers from 2 to 100 Give both the pseudocode version and the flowchart version Convert your pseudocode into a Java program?

Develop an algorithm to display all prime numbers from 2 to 100. Give both the pseudocode version and the flowchart version. Convert your pseudocode into a Java program.


What is an English-like statement used to describe the logic of a program?

Pseudocode.


What has the author T E Bailey written?

T. E. Bailey has written: 'Program design with pseudocode' -- subject(s): Programming, Electronic digital computers, Electronic digitalcomputer, Pseudocode (Computer program language)


How do you write a pseudocode program for finding out x to the power of y?

X**y


Is pseudocode a combination of programming language and machine code?

No. Pseudocode is not used to write complete programs; rather, it is an overview of what you want to achieve. For example, the following pseudocode is for a program to print a list of square roots: for i = 1 to 10 show i, i*i A specific programming language may not have a "show" command, and the structure of the "for" loop might be different; additional setup and cleanup commands may also be required in a real computer program; the purpose of this pseudoce is merely to explain, to a human, what you want to achieve. The real code, with more detail, will have to be added later.


Pseudocode could be logically incorrect if not properly indented?

The indentation doesn't affect the "logic" of the program, however it would make it make harder to read and the purpose of pseudocode is to be read.


Could Pseudocode could be logically incorrect if not properly indented.?

The indentation doesn't affect the "logic" of the program, however it would make it make harder to read and the purpose of pseudocode is to be read.


Display a pseudocode for a calculator program?

firstly try yourself then ask others or browse internet websites etc


Write a pseudocode for a program that accepts two integers and substract 5 from the answer?

1. Accept the 2 numbers 2. Add the 2 numbers3. Compare answer with 54. If answer is greater than 5 subtract with 5 else give a error message.


How do you write the semicolon symbol in a pseudocode logic program delaing with classes?

Any of these: PRINT semicolon EMIT ; WRITE ";" etc.


Why is pseudocode important to programmers?

Pseudocode lets a programmer lay out his intended program in a simple to understand method and run it through in his head before putting his fingers on the keyboard. Programming is a complex process and needs some degree of planning beforehand to avoid mistakes and confusion later on.


What is pseudecode?

I assume you are saying pseudocode, which in that case are words in plain language with the aim to explain the code of a program or algorithm. If that's not what you meant, then sorry to disappoint.