0% found this document useful (0 votes)
147 views

Lab Assignment 11.1

This document outlines 10 programming assignments involving algorithms for natural number operations, prime number checks, factorials, greatest common divisors, and digit sums. Students are asked to write pseudocode, draw flowcharts, and provide sample outputs for programs that print the first 10 natural numbers, calculate sums of ranges, check if a number is prime, find prime numbers within a range, calculate factorials, and find the divisors of a positive integer.

Uploaded by

Shehe athumani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Lab Assignment 11.1

This document outlines 10 programming assignments involving algorithms for natural number operations, prime number checks, factorials, greatest common divisors, and digit sums. Students are asked to write pseudocode, draw flowcharts, and provide sample outputs for programs that print the first 10 natural numbers, calculate sums of ranges, check if a number is prime, find prime numbers within a range, calculate factorials, and find the divisors of a positive integer.

Uploaded by

Shehe athumani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

THE UNIVERSITY OF DODOMA

COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION

CP 111: PRINCIPLE OF PROGRAMMING LANGUAGES

GROUP ASSIGNMENT (Individual presentation)

1. Write an algorithm in pseudocode for a program to print the first 10 natural numbers.
Sample output:
The natural numbers are: 1 2 3 4 5 6 7 8 9 10.

2. Draw an algorithm in a flowchart for a program to find the sum of the first 10 natural
numbers. Find the first 10 natural numbers:
Sample output:
The natural numbers are: 1 2 3 4 5 6 7 8 9 10.
The sum of first 10 natural numbers: 55.

3. Write an algorithm in pseudocode for a program to display n terms of natural number and
their sum.
Sample Output:
Input a number of terms: 7.
The natural numbers up to 7th terms are: 1 2 3 4 5 6 7.
The sum of the natural numbers is: 28.

4. Draw an algorithm in flowchart for a program to check whether a number is prime or not.
Sample Output:
Input a number to check prime or not: 13.
The entered number is a prime number.
5. Write an algorithm in pseudocode for a program to find prime numbers within a range.
Sample output:
Input number for starting range: 1.
Input number for ending range: 100.
The prime numbers between 1 and 100 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53
59 61 67 71 73 79 83 89 97.
The total number of prime numbers between 1 to 100 is: 25.

6. Draw an algorithm in flowchart for a program to find the factorial of a number.


Sample output:
Input a number to find the factorial: 5.
The factorial of the given number is: 120.

7. Write an algorithm in pseudocode for a program to find the last prime number occurs before
the entered number.
Sample Output:
Input a number to find the last prime number occurs before the number: 50.
47 s the last prime number before 50.

8. Draw an algorithm in flowchart for a program to find the Greatest Common Divisor (GCD)
of two numbers.
Sample Output:
Input the first number: 25.
Input the second number: 15.
The Greatest Common Divisor is: 5.

9. Write an algorithm in pseudocode for a program to find the sum of digits of a given number.
Sample Output:
Input a number: 1234.
The sum of digits of 1234 is: 10.
10.A program reads a positive integer entered by an interactive user and then prints out all the
positive divisors of that integer in a column and in decreasing order. The program should
allow the user to repeat this process as many times as the user likes. Initially, the program
should inform the user about how the program will behave. Then the program should
prompt the user for each integer that the user wishes to enter. The program may be
terminated in any of two ways. One way is to have the program halt if the user enters an
integer that's negative or zero. In this case, the user should be reminded with each prompt
that the program can be terminated in that way. Alternatively, after an integer has been
entered and the divisors have been printed, the program can ask the user whether he/she
wishes to enter another integer. In this case, when the user accidentally enters a zero or
negative integer to have its divisors calculated, the program should inform the user that the
input is unacceptable and should allow the user to try again (and again!).
a. Use the DDIV chart to summarize the scenario.
b. Use the IPO chart to summarize the scenario.
c. Write an algorithm in a pseudo code for this program.
d. Draw an algorithm in a flow chart for this program.
e. Use the RAM diagram

You might also like