#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Two simple programs. Help!

Posts: 2Member
I need help with these programs. Truth is, I've never used pascal to program something.

Text:

1. Write a program which will allow you to input 3 digits number and than will calculate and write sum of that numbers.

2.Write a program which will allow you to input natural number N and than will write sum of numbers from 1 to N.
· ·

• Posts: 438Member
: I need help with these programs. Truth is, I've never used pascal to
: program something.
:
: Text:
:
: 1. Write a program which will allow you to input 3 digits number and
: than will calculate and write sum of that numbers.
[blue]
First input the number N.

The least significant digit of N will be N mod 10. If you will not be needing N later in the program you can get the subsequent digits by dividing N by 10 using integer division which throws the remainder away, i.e,. N := N div 10.

For example, if N = 123 then N mod 10 = 3, the least significant digit.

Now using integer division N div 10 = 12.

The next digit is N mod 10 = 2

N div 10 = 1

N mod 10 = 1

so the three digits that need to be added together are 3,2, and 1.

[/blue]
:
: 2.Write a program which will allow you to input natural number N and
: than will write sum of numbers from 1 to N.
:
[blue]
The formula for this is

Sum := N * (N + 1) div 2
[/blue]
· ·
• Posts: 2Member
: : I need help with these programs. Truth is, I've never used pascal to
: : program something.
: :
: : Text:
: :
: : 1. Write a program which will allow you to input 3 digits number and
: : than will calculate and write sum of that numbers.
: [blue]
: First input the number N.
:
: The least significant digit of N will be N mod 10. If you will not
: be needing N later in the program you can get the subsequent digits
: by dividing N by 10 using integer division which throws the
: remainder away, i.e,. N := N div 10.
:
: For example, if N = 123 then N mod 10 = 3, the least significant
: digit.
:
: Now using integer division N div 10 = 12.
:
: The next digit is N mod 10 = 2
:
: N div 10 = 1
:
: N mod 10 = 1
:
: so the three digits that need to be added together are 3,2, and 1.

:
: [/blue]
: : Ok. I solved the program number 2. But I can't make program number 1 to work. Is there any chance that you post a code?
: : 2.Write a program which will allow you to input natural number N and
: : than will write sum of numbers from 1 to N.
: :
: [blue]
: The formula for this is
:
: Sum := N * (N + 1) div 2
: [/blue]
:

· ·
• Posts: 438Member
: : : 1. Write a program which will allow you to input 3 digits number and
: : : than will calculate and write sum of that numbers.

: : : Ok. I solved the program number 2. But I can't make program number 1 to work. Is there any chance that you post a code?

[code]
IN PSEUDOCODE