Algorithm Exercises for Number Manipulation
Algorithm Exercises for Number Manipulation
1
Develop an algorithm that takes 2 numbers as input and indicates the relationship between them.
indicate the largest, the smallest or specify if they are equal
Exercise No. 2
Given 3 numbers, check whether they can be the lengths of the sides of a triangle.
considering that none of the sides can be greater than or equal to the sum that
the other two
Exercise No. 3
Read A, B, and C and sort them in ascending order using D as an auxiliary field.
assuming that the contents of A, B, and C are unknown, print the ordered variable
Exercise No. 4
Having two numeric variables A and B, swap their contents without using any
auxiliary field
Exercise No. 5
Read N numbers, each with a variable X, develop an algorithm to verify if the
Records are sorted in ascending order. The last non-processable record is 0.
Perform the desk test with 10 values.
Exercise No. 6
Input N numbers, each with a numeric variable A, select those that are
greater than 5 and sum them, print the result and the amount of records that do not
they met the condition
Exercise No. 7
Read N numbers into a numeric variable X, write an algorithm that allows you to control.
ascending correlating sequence of the same. Print the records out of sequence,
ignoring them for control. The first does not necessarily start with 1.
Exercise No. 8
Enter N numbers each with a variable X, print the average sum.
of every 3 consecutive values.
Exercise No. 9
In a laboratory, the temperature of the ovens measured in degrees is recorded every hour.
Celsius, each record contains the following information time-temperature. It is desired
Convert the temperature to degrees Fahrenheit, according to the following formula:
F = (9/5.Cº + 32)
For each record print:
Hour, degrees Celsius and degrees Fahrenheit, there are 24 records per day.
Exercise No. 10
Given n numbers, find the largest and the smallest, printing both with the messages of
respective identification
Exercise No. 11
There is a file with n records; each of them with a numerical variable X,
print the range of the file. Range = Largest number - Smallest number
Start
N = 0, c = 0, may = 0, men = 0, x = 0,r = 0
Enter the number of numbers
Read n
While c < n
C=c+1
Read x
If c = 1
x
Men=x
Who
If x<men
Men=x
Who
If x > may
May=x
End if
End if
End if
End While
R = may - men
The range is:
beginning
Exercise No. 12
Read the variables A, B, C, and D, check that A belongs to the open interval (C, D) and that B
do not belong to the same if the 2 conditions are met, add A and B, otherwise subtract A from B,
print A, B and the result
Exercise No. 13
Build an algorithm that allows you to obtain the sum of the squares of the first 50
natural numbers
C = repetition counter
S = sum of squares
Exercise No. 14
Build an algorithm that allows obtaining the factorial of a given number. The factorial of
A number is the result of multiplying that number by the values lower than itself.
up to one. The factorial of 0 is 1
Exercise No. 15
There is a file whose records have the following fields.
Nº de alumnos (n)
number
3rd course. We know that the values of the following fields can be: Gender 1.-
Female
Single
Married
Others
Exercise No. 16
There is a file with n records. Each of them with the following fields
Day-Month-Year and 12 data points corresponding to the temperature of a day, taken at intervals
2 hours. Calculate the average temperature of the day and print it with the date, repeat the
processes with the N records.
Exercise No. 17
Create an algorithm that allows finding the product of two numbers using the method of
successive sum. The numbers must be integers and greater than zero.
Exercise No. 18
Given two variables N and M, find the quotient of M/N by successive subtractions. M may or may not
be a multiple of N but is always greater
Exercise no. 19
Enter a number and find out if it is even or odd
Exercise No. 20
There is a file with N records, each of them with a variable X. Find out
what are the multiples of 3 and print them
Exercise No. 21
There is a file with N records, each with a value X. Calculate the average.
of even and odd values. Print both averages.
Exercise No. 22
There is a file with N records, each of them with a value X. Create an algorithm.
To know if each given X is a multiple of 3, 5, or both. Print the quantity of
record that meets each condition
Exercise No. 23
There is a file of K records, each with 2 variables A and B. Verify
that A is divisible by 3 and that B is even (Use the method of successive sums and
successive subtractions) in case both conditions are met multiply A * B and print
the resulting values. Otherwise, print A and B (note: A and B are integers greater than)
of 0)
Exercise No. 24
There is a file with K records, each with 2 values A and B. Make a
algorithm that allows:
If A is greater than 0 and B is greater than A, R = A * B (by successive addition) Print
If B is greater than 0 and less than or equal to A, check if A is a multiple of B.
successive subtractions
Print the average of the calculated products
Print the number of records whose products were not calculated
Exercise No. 25
Knowing that a number A is divisible by B if the division is whole, create an algorithm in
the one given A and B
I=2 if A divides B (b/a)
I=3 if B divides A (a/b)
I=4 if A divides B and B divides A (a=b)
I=5 if none of the previous requirements are met
Exercise No. 26
Read a number N greater than 100 and find and print the numbers up to N that are
odd numbers that are not multiples of 5, also find the sum, the product, and the
average of the found numbers and print these values as well as the amount of
number that met the condition
Exercise No. 27
It is desired to know how many times a negative value is followed by a positive value. Print it.
amount found. N values are entered one by one.
Exercise No. 28
Develop an algorithm to add two 4-digit numbers A and B.
storing each digit in a separate position. The digits of A will be located in D4, D3
D2, D1 and those of B in W4, W3, W2, W1 the answers must be given in the positions, A4, A3
A2, A1 respectively
Exercise No. 29
Read a 5-digit integer and print the hundreds.
Exercise No. 30
A date is entered in the variable F (year, month, day) in a 6-digit numeric variable.
print year, month, and day separately Example
85
Exercise No. 31
Create an algorithm that describes the following process. Two 4-digit values are read.
Calculate and print a new number that consists of the 2 highest order digits of
the first quantity and the 2 of lesser order of the second quantity placed one at
continuation of another. Ex.
1234
Exercise No. 32
The fields: Article number-notary price-Existence-Minimum stock-Value of
existence. They correspond to each record of a stock file. A listing is needed of
all the articles that meet the following conditions:
Exercise No. 33
Calculate and print the sum and the product of the integers that belong to the
open interval (M……N)
Exercise No. 34
Develop an algorithm that prints the sum of 100 + 98 + 96 +...... 40
Exercise No. 35
There is a file of T records, each with the variable x. Calculate its F (x)
corresponding and then print X and f(x) knowing that:
2
F(x) = x - x If it is greater than 5
F(x) = 71 If it is greater than or equal to 5 and less than or equal to -2
F(x) = x + 10 If x is less than -2
Exercise No. 36
Read a number N and assign the variable C a value of 1 if N is a perfect cube;
if assigning to C, its value is 0
Note: A number is said to be a perfect cube if there exists a number x such that the cube of x
be equal to the number. Repeat the process M times
Exercise no. 37
A positive integer N greater than 1 is a prime number if the only integers
positive divisors that divide it exactly are 1 and N
Prepare an algorithm that allows a positive integer N and prints the message IS
COUSIN or NOT COUSIN
Print all prime numbers less than or equal to N
Exercise No. 38
Develop an algorithm that takes a number and breaks it down into its factors
cousins. Print the results
Exercise no. 39
Read a number M and then find a number N such that 2 * N is less than or equal to M.
but 2 * (N-1) is greater than M
Exercise No. 40
There are 50 records each with 3 values A, B, C. Create an algorithm that calculates the summation.
of the values, being X
Exercise No. 42
Make an algorithm that prints the first N
terms of the Fibonacci series
The Fibonacci series is: [Link].[Link]…
F A c n
0
Read n
Show f
F=1
A=0
C=1
While c < n
C=c+1
Show f
A=f
F=f+a
End while
Exercise No. 43
Prepare an algorithm to print the 3 digits from the right end of 100 terms of the
Fibonacci series, starting from the seventeenth. Estimate how many of these 100
The numbers will be even. How many are greater than 500 and how many are between 300?
y 400
Exercise No. 44
Starting from an employee file, whose records contain the fields: Numbers of
employee-Salaries, the directory of a company requested the preparation of a list that
Indicate how many of your employees earn up to G 20,000 and how many earn between 20,001 and
30,000, how many between 30,001 and 40,000 and how many more than 40,000
Exercise No. 45
There are 400 employees in a company and a monthly settlement is desired. The
Salaries vary between Gs. 100,000. All employees have a fixed discount of 8%.
for retirement and or three discounts that follow the next rate
:
If the salary is less than or equal to 25,000, no extra discount.
If the salary is greater than 25,000 and less than or equal to 50,000, 5% discount
extra.
If the salary is greater than 50,000 and less than or equal to 75,000, 6.5% discount
extra.
If the salary is greater than 75,000, an extra 7.5% discount.
Exercise No. 46
The employee file of a company is recorded on disk, for each employee it
it has a record with the following format;
employee_number
2)
Create an algorithm that allows obtaining the payroll sheet for salary settlements from the
file:
The form must include the following data:
Number of employees
The payroll settlement will be made according to the following rule: net salary to be paid =
Salary - discount (5% or 10%) of the salary. The last non-processable record has 0 in
the field Number of employees. In the end, it wants to know the total net to be received by women and
total net to be charged men.
Exercise No. 47
The file of second-year students of the computer science degree at UNA.
Each student has a record with the following format:
Student number
first course
Print the student number and name of the one who had the lowest score, if there is more than one.
consider the last one
Exercise No. 48
The information regarding the books of a bookstore is entered into the computer, each
The record has the following information: book code, description, unit price,
monthly demand, inventory, author. A list of books that meet the criteria is desired.
some of the following requirements:
The unit price is less than or equal to 1500, if it is higher, then its demand
monthly is greater than 30
Existence is less than 15 or, if it is greater than or equal to the demand, it should be
greater than 25.
The last record has a negative book code. The list must include the name.
del libro
Exercise No. 49
The file of students who have taken the entrance exams at the faculty,
It is recorded on disk and for each student there is a record:
student_number
Spanish - Aptitude Test
The scores by subject range from 1 to 100. Create an algorithm to print the
following points:
Exercise No. 50
There is a file that has the following fields in each record: number of
empleado – nombre – sexo (1- Fem.; 2 mas) -sueldo – cantidad de hijos. Utilizando el
described file, create an algorithm that allows for:
employee number
less than or equal to Gs. 40,000
Listar número de empleados – nombre – sueldo – cantidad de hijos de las
women with a salary greater than Gs. 70,000 and with more than two children.
Search and print the name and salary of the employee with the highest salary and count
print the number of men and women employed in the company
Exercise No. 51
There is a file containing a record for each employee of a company. Each record
tiene los siguientes campos: numero de empleados – nombre – sexo - (1- mas; 2 Fem.)
- salary - deduction - net salary. Create an algorithm that allows reporting:
Number of men with net salaries greater than Gs. 50,000
If there was any man with a negative net salary
There were women with a salary greater than Gs. 100,000
Exercise No. 52
A company has the file of its employees recorded on disk, for each one it has a
record with the following format: Name - sex - age - number of children - salary. It is
wish
Print the names of all males under 25 with more than 1 child
a salary less than Gs. 45,000
Print number of women with children
Number of men with 3 children and a salary less than or equal to Gs. 50,000 or greater
40 years old.
Total of men
Exercise No. 53
Read 3 variables A, B, and C that come in a file of 2,000 records, check the
following conditions:
A must be equal to 50 or less
B must be at least 5 and no more than 8.
C must be at least 4
Exercise No. 54
The records of a stock file have the following fields: Date (day, month, year) -
order number - warehouse number - batch number - stock - number of
provider.
It is desired to validate the mentioned fields by saving the file of valid records with the
correct records and print the incorrect ones.
Validation rules:
Date: it should be a logical date
Order number: must be greater than or equal to 10
Warehouse number: from 1 to 5
Existence: must be greater than the minimum stock
Supplier number: it can be 1, 2, 3, 9, 10, 11.
Exercise No. 55
Validate the fields of the stock transaction file whose records have the
following fields: number - location - warehouse - deposit - existence.
Exercise No. 56
Detectives are to be selected for an international mission, for which there are
a file of agents, whose records have encoded fields as follows
manera: sexo (1-fem, 2-masc). Estudios (1- universitario, 2-especialización, 3-otros),
estado civil (1-soltero, 2-casado, 3-divorciado, 4-viudo). Nombre, Sueldo, Antigüedad,
Languages (1-10). The personnel suitable for this mission must meet the following requirements:
a) If it is female:
Age: 20 to 35 years
Completed studies: university or specialization
Language. Accept only codes from 1 to 3
Estado civil: 1, 2, 3, 4.-
Basic salary: no more than Gs. 1,000
b) If the sex is male:
Age: 22 to 45 years
Studies completed: university or specialization if you have at least 3 years of
antiquity.
Language: accept codes from 1 to 3
Marital status: if married, accept; if not, have more than two children.
Basic salary: No more than G. 1,500
Print all records that meet the stated conditions.
Exercise No. 57
If you have a batch of N records, each with data of the 11 final grades of the
students of a school and their names. It is desired to calculate the average term.
what corresponds to it and print it in a list that contains:
Name - Final Notes - Average Term - Repeat the process until the file is finished
Exercise No. 58
Prepare a report on the existence of items. For this, a file is available.
stock master, where each record has among other fields: Identification number of the
article and existence
Write notices in case of:
Every time there is a message, the identification number must also be printed.
article.
Exercise No. 59
A company has a sequential file sorted by employee number, of all
the employees. In each record there are, among other fields: employee number, name and
a code that can be 1, 2, or 3 (married, single, others). It is desired to list the number and
name of each employee indicating whether they are married, single, or other: having in
account:
Exercise No. 60
Knowing that there are 1,000 students in the Faculty and that the file records the
siguientes datos por cada alumno: numero de alumno – nombre – sexo – edad – curso
Create an algorithm to find the oldest male student.
and the youngest female student. Print the following data of those students:
Student number.
Age
Course
Código del sexo: 1-masc. 2- Fem.
Exercise No. 61
There is a file containing data about the cities of the country, each record
contiene. Código de la ciudad – nombre de la ciudad – distancia a asunción en km.
Create an algorithm that allows finding which is the farthest city and which is the closest.
close to Asunción. Finally, print the names of the cities and the distances from them.
same to Asunción. The last unprocessable record has 0 in the Code field.
City. In the search for those cities, Fdo. De la Mora should not be taken into account.
in Lambaré, whose codes are 1 and 7 respectively
Exercise No. 62
There is a set of records, each of them with the following data:
In the end, the sum of the amounts paid is desired. Possible errors must be anticipated.
(M2 < M1, etc.)
Exercise No. 63
Clave
Name. It is desired to know and print for each client the corresponding amount that
the result of each record, which will be calculated according to its key in the following way:
Exercise No. 65
Develop an algorithm that simulates a dice game. In this game, the player rolls
two dice. (Represented by A and B). If on their first roll the sum of the values of
if the first roll is 2, 3, or 12, he
loses: in the other cases (4, 5, 6, 8, 9 or 10) the player must continue rolling until:
Complete the sum of the two dice the original value of the first roll (4,
5, 6, 8, 9 or 10) which results in a gain of 0
Complete the sum of the two dice to make 7, which means you lose.
The algorithm must generate two random numbers (A and B) between 1 and 6 each.
through the function RAM (7,6). EXAMPLE: A=RAM (1, 6) creates a value between the
one and 6 and store it in variable A: add both values and print the result
accompanied by the corresponding messages ["You win", "You lose", "Pull from
new, etc.
Exercise No. 66
Exercise No. 67
Using the function (ENT A): An algorithm is desired that reads a number
A 10 digit number and determine and print the number of decimals it has, knowing that
At least one of the figures is an integer. Then it is necessary for the value of A to be converted.
to an integer rounding it by the rule that states that a digit greater than or equal to 5,
in the decimals, increase the immediate higher digit by 1 (be careful with the
increase of whole numbers). Place the whole value in variable B and print it
as in the examples.
A= 32.54892212 obtiene B= 33 – Cantidad de decimales 8
A= 2.358654545 obtiene B= 2 – Cantidad de decimales 9
A = 325489.8212 obtains B = 325490 - Number of decimals 4
Exercise No. 68
There is a file of the goods of a pharmacy, whose record contains the
following data:
CODPRO Product code
MONPRO Amount of the product
TIPMED Tipo de medicamento (1= Pastillas, 2= Jarabe, 3= Pomada, 4=
Others)
The end of the file is indicated by a record whose CODPRO = 0 that must not be
processed. An algorithm is requested that detects and prints the registration data that
meet the following condition: That the medications have their code of
product between 1,000 and 5,000 inclusive and the amount of the Product is greater than 35,000
It is also desired to know the data of the medications whose type of medication
equal to 4. Indicate at the end of the process how many records met all the requirements.
requested conditions.
Exercise No. 69
There is a STOCK FILE of goods, whose records contain the
CODE
algorithm that:
Print the code and description of the item that has stock (Quantity)
less than 0. At the end print.
The number of records that met the condition
Print the total value of the products that exist (Sum of QUANTITY
* PRICE)
Exercise No. 70
Develop an algorithm that allows the reading of three values.
numerical. Determine which of them is the largest and the difference
existing between it and the one with the lowest value. Print the
values. Repeat the process until 0 is entered in the first
value.
Exercise No. 71
There is a data file that has the ages of the students in a course, it
You know that there are 60 in total, create an algorithm that determines the average of
ages of the course.
Exercise No. 72
Develop an algorithm that calculates the sum of 25 consecutive numbers.
entered one by one and if the result is greater than 500 print a message to
regarding, otherwise ignore it.
Exercise No. 73
Develop a pseudocode algorithm that allows checking if it is prime or not.
number greater than or equal to one, entered via keyboard. Print the result
Exercise No. 74
Develop an algorithm that allows the reading of three numerical values, determine if
they are the same or different, in case they are the same print a message, case
opposite of the sum of the three, repeat the process until 0 is entered in the first
value
Exercise No. 75
Develop an algorithm that reads the data related to the
measures of land, calculating its area
(Area = (Length x Width) / 2), printing the results
if they are larger than 550 m2. Otherwise, indicate by
through a message that the values are not enough.
Exercise No. 76
Develop an algorithm that allows the entry of 50 three-digit numbers, all
different and real, and determine those that are palindromes, meaning they have the same value
read from back to front or vice versa. Examples: 323, 525, 222, etc.
In case there are 'Print them', at the end print the number of palindromic values.
found.
Exercise No. 77
There is a data file that contains the names and grades of Workshop I.
students of the course, the exact number of which is unknown. Create an algorithm that
determine the names of the students with the best and worst grades, as well as the difference
between both and finally the average of the course.
Exercise No. 78
Develop a pseudocode algorithm that allows processing the data from the file
student grades from the POLYTECHNIC Faculty in the subject Workshop I (Subject =
11), only for those who took the First Partial (Subject = 111). The process must be
determine the NAMES of the students with the highest and best scores, the average of
the subject and the range (difference between the highest and lowest score). The grades file
he has the data for all the exams of all the subjects of the faculty, therefore
only those requested in this statement should be processed, the data from the file are:
Student number, name, Exam Subject, Grade. The end of the file is marked by the
record with value Student Number = 0, which should not be processed.
Exercise No. 79
Develop an algorithm that allows determining in the company's Employees file
SOCRATES LTDA. The total number of employees with a salary greater than 500,000 gs.
The names of those female officials have a salary below the minimum.
(The minimum wage must be read at the beginning in the SALMIN variables). The file contains
with the following data. Name of the official, Gender (F/M) and the salary amount.
Finally, print the average salaries of the company.
Exercise No. 80
Develop an algorithm that allows the validation of the fields of the file
inventory of merchandise where each record has the following data: Code of
must be greater than 5,000 and less than 10,000
greater than 70
If the stock is less than or equal to the minimum quantity, print.
URGENT – Buy immediately and consider it as an error.
If the values found in the fields do not match the allowed ones, print a
error message, indicating in which field the error was detected.
Print at the end the number of errors detected for each field, and the total number of errors.
from the file.
VECTORS
Exercise No. 1
Create a vector with the data from a file. Each record has a numerical variable.
Finally, print the elements of the vector.
Exercise No. -2
Create a vector according to the following rules: Load 1 in (1). 2 in V (2). ... N in V(N)
,¿
Exercise No. 3
A vector A of length N is stored in memory. Make an algorithm that prints all
the positions of the elements of A that are equal to a read X.
Exercise No. -4
Design an algorithm to create a vector V. with all the ages of the students.
fourth course of Analysis. From the vector calculate the average age.
Exercise No. -5
Given a vector of N elements, create an algorithm that allows finding the largest and the
smallest element of the vector with its respective positions.
Exercise No. -6
Read 2 vectors A and B, both of length N, and then calculate and print:
The vector C which is the sum of A and B, knowing that each C(i) = A(i) + B(i).
Assume that A and B are of dimensions M and N respectively.
Exercise No. 7
Analyze whether two vectors A and B read are equal knowing that the dimensions of A and
B is son N and M respectively.
Exercise No. -8
It is maintained in vector A of N elements. Create an algorithm that allows obtaining the
sum of all elements located in even positions.
Exercise No. -9
Read a vector with N components and then find the sum and the average of the
components that are in even locations and those that are in positions
odd.
Exercise No. 10
Create an algorithm that allows counting the elements of the vector V that are multiples.
from 3 and 5, the average of the elements located in is also desired
odd positions.
Exercise No. - 11
A vector A of N elements is stored in memory, create an algorithm to start from
From A, another vector B is created such that the elements of B are the elements of A that are greater.
what 5.
Exercise No. 12
A vector V of N elements is stored in memory. Create an algorithm that allows
Find and print the median. Median is the central middle element if N is odd.
If N is even, the median is the semi-sum of the two central values.
Exercise No. - 13
A vector A of N elements and another vector B of N-1 elements are stored in memory.
Create an algorithm that allows forming a vector C with the elements of A and B such that:
C (i) = A (i + 1) + B (i).
Exercise No. 14
A vector B of size N is stored in memory. Create an algorithm that allows to create a
vector from B such that each A(x) = B(x) - the largest element of B() .
Exercise No. 17
A vector A of length N is stored in memory. Create an algorithm that allows for the creation of
the vectors B C and D such that:
B contains the elements of A that are different from 0
C contains the elements of A that are even.
D contains the elements of A that do not meet the previous conditions.
Exercise No. -18
A company wants to minimize the number of bills it needs to pay its
personal. Create an algorithm that solves the problem.
Exercise No. 19
Given a vector A of N elements (N is even) Create an algorithm that allows to create a
vector B such that the first half of B is each element of the first half of A
multiplied by the largest element of A and the second half of B is the second half
A multiplied by the smallest element of A.
Exercise No. - 24
Find the union of A and B in a new vector C, so that the vector C does not have
repeated elements.
Exercise No. - 25
A vector A of dimension N is read, compress the read vector by eliminating zeros and
shifting the remaining elements to the left closing the rest of the vector.
Print the remaining vector.
Exercise No. - 26
Given a vector A of N elements, create an algorithm to find the mode(s).
The vector is ordered in ascending order. The mode is the element that occurs most often.
repeat. If there is no mode, print the corresponding message. The elements range from 0
at 9
Exercise No. - 27
There is a vector of N elements. Create an algorithm to sort the vector.
ascending in the following way: first the even numbers, ordered accordingly
the odds must be sorted, also in ascending order, following the
Ordered pair components. All of this is done in the same vector without using vector.
to assist someone.
Exercise No. - 28
There are 2 vectors A and B in memory, each with N components. The elements of A are
arranged in ascending order and all are different. Read a number P. Make a
algorithm that searches in A for the element closest to P and prints the element from B
that has the same index as the element of B located in the lowest position.
Exercise No. - 29
Knowing that the vectors P. A. M of size H. J. I. are stored in memory.
respectively. Create an algorithm that allows creating a vector Z of such size
so that P is the first part of Z. Next to this and M is the last part.
Exercise No. - 30
A vector A with N components is held in memory. The variables L are also available.
y M. such that L, N and M. L Create an algorithm that allows converting all to zero
elements of A pairs understood between A (m) and A (n) and that convert to ones all
the odd elements between A (I) and A (L) including the ends.
Exercise No. - 31
Read a vector B of N components and an integer A and find the smallest.
element of the vector that is greater than the read A.
Exercise No. - 32
Find the dot product of two vectors read if:
both are of length N
N is of dimension M and B is of dimension N
Example:
A = (1,2,3)
B – (4, 2, 1, 3, 8)
Dot product (1*4) + (2*2) + (3*4) + (0*3) + (0*8)
Exercise No. - 33
In a city, a survey was conducted to determine the number of inhabitants.
belong to each of the religions. Each inhabitant has a record that
you have the following code.
Catholic
Lutheran
Jewish
Others
None
End
Determine the number of inhabitants adhering to each of the religions and the total.
inhabitants of the city.
Exercise No. - 34
A test is taken that consists of 25 questions, each of which has 3 possible answers.
answers, with only one correct. Each record has the Student Number and the
25 answers given (ordered by the number of questions)
Create the flow algorithm to obtain a list that contains the number of students and
the number of correct answers given.
They enter as data:
SOLUTION
Data analysis
Using the name (RESP) to identify the students' answer file
we observe that it has the following structure and characteristics:
There is also a vector (COR 25) that must be loaded at the beginning of the algorithm, for
through a prior reading and that contains the correct answers to the questions of the
exam. The operator should be given the opportunity to check and correct the
responses to be inserted, for which there is a validation subroutine for that purpose.
Unknown
This is the most important point of any algorithmic exercise, as it is already
Effective identification of the unknown is almost 50% of the exercise.
RESP Response file
Pseudocode
Once the data, characteristics, and unknowns are available, the start can be given to
development of the solution in pseudocode using the structures and definitions of
this tool, in this particular case the result can have the following
presentation.
Exercise No. 35
Read a vector A of N components and create and print a vector B, which is composed of
for all the components of Vector A that are not repeated
Exercise No. 36
There are two vectors A and B, each with 100 positive integer components. Compare them.
corresponding components of A and B (this is called the components that occupy the
same positions, for example: A(1) with B(15)… A(100) with B(100)
Create integer vectors called SEMI, MAYO, MENO, COCI, and RESI where each:
Print at the end for each number from 1 to 100, the corresponding A (i), B(i), SEMI (i).
MAYO
Exercise No. 37
It is desired to form a vector whose first two elements are the given numbers (M and N)
and each subsequent element is the remainder of the division of the previous two. The sequence
ends when an element of it is zero. Print the vector, the dimension and the
element of the vector that precedes the zero. This algorithm is the Euclidean algorithm for
find the G.C.D of 2 numbers M and N, being G.C.D the element of the vector that precedes the
zero
Exercise No. 38
A vector K of dimension m is read, and a vector L of dimension N, each of which
contains different positive integers.
Store in another vector the intersection of vectors K and L, that is, those
elements that are in both K and L.
Store in another vector the union of the vectors K and L, or all those
elements that are in K, or in L, or in both.
Store in another vector the symmetric difference of vectors K and L, that is
those elements that are in K or in L, but not in both.
Example.
K= (1, 3, 2, 5) L= (1, 5, 4, 7, 8, 3)
Exercise No. 39
Read in N a number of K digits. Form the largest and the smallest number that
can be obtained by permuting its digit figures.
Print the number N read, the largest number, and the smallest number found.
Repeat the process 1000 times, reading K and N each time.
Example
K= 5 N= 31270 (5 digits)
Number read = 31270
Greater found = 73210
Least found = 01237
Example: ([Link].-1.20)
Ordered vector = (-[Link].5.3)
Exercise No. 41
Read a vector A with N components and create the vector with N components where each:
B(i)= 1 for 1 = 1
B(i) = summation of the squares of the elements of the vector from position 1 to
i-1
Examples: B(i) = 1
A(1)^2
B(3) = A(1)^2 + A(2)
Exercise No. - 42
Read a vector A of N components and calculate the vectors B and each of N
components where:
Exercise No. - 43
Read a vector X of 50 components and calculate the vector DX where each DX(i) = X(i+1) -
X(i)
Exercise No. - 44
Calculate the mean and the standard deviation of the elements of a vector X of N
components, knowing that: average = sum of vector elements / number of
elements.
To find the standard deviation, follow these steps:
Read vector:
232 45 1221 1 11111 45554
Printed vector:
1 3 5 6
Exercise No. - 46
Given the vector ORD(N). Loaded with numerical values, develop an algorithm that
allow sorting it from smallest to largest (develop the desk test with 4 elements
from values 1 to 4, checking the correct functioning of the algorithm.
Exercise No. - 47
Develop an algorithm that loads the vector VEC(N) with data entered from the keyboard.
checking that they meet the following conditions, the first element
it must be 1, the second must be 2, and from that moment each element must be equal
to the sum of the two previous ones, that is, the third must be 3, the fourth element must be
5, the fifth must be 8, etc...; in case the entered data does not correspond to a value
It is valid to print a message "Invalid data". The process must conclude with the loading of N.
elements and then print the loaded vector and the number of detected errors.
Exercise No. - 48
There is a FILE that contains the data of a marketing company.
grains, each record has the following format:
Exercise No. 49
Given a FILE that contains the data of a marketing company
oils, each record has the following format:
NROCOD - Oil code number, (1=Kitchen - 2=Engine - 3=Common -
4=Superior – 5=Super fine
VEC(12) –Vector of twelve elements, with the results obtained in each type
of oil quality testing, possible values from 0 to 50.
DIAPRU – Day of the completion of each test.
MESPRU – Month of the completion of each test.
Develop an algorithm that allows calculating the average of each of the tests.
monthly tests conducted (there are 12 types of possible tests), regardless of the type of oil.
Detect the type of oil with the highest number of tests conducted monthly and in which month.
It happened, print the results found
Exercise No. - 50
Develop an algorithm that allows verifying the order in which the data was loaded.
in the vector VEC(N), arranged in order from smallest to
greater, whether even or odd, that is to say, the even values in the even positions and the
odds in the odd positions, each of them sorted from least to greatest. If a
value does not follow the indicated order, sort it properly, continue until everything is verified
the vector, in case no errors have been detected, print a message indicating that
the vector is correctly ordered: if there were errors, print the quantity of them
the same. It is known for certain that even values are in even positions and that the
odds are in odd positions, the algorithm should only verify and correct the order
ascending of each type (duplicate values may exist and they must be
processed). Example:
1 4 3 2 9 4 7 6
VEC – initial
1 2 3 4 7 4 9 6
VEC – Final
Total de errores:4
Exercise No. - 51
There is a file that contains the students' data from the faculty.
polytechnic, according to the following structure:
CIN number
installment (5) [Vectors with the monthly amount to be paid during the semester].
[vector with the due dates, format YYMMDD, of the payments to be made
in the semester]. MAT (8) [Vector with the course codes in which the student is
enrolled in the semester]. ASI (8) [Vector with the attendance percentages of each
subject in which the student is enrolled]. LIB (5) [vector that indicates the codes of
books that the student owes.
It is desired to inquire about the students eligible for which the date of the day is entered.
TODAY (format YYMMDD) and a list is requested that contains for each student the
information indicating in which subject one is enabled, for which it will be checked that not
Any fee to date, which has attendance greater than or equal to 75% and does not
I took the book from the library. At the end, indicate the number of students not authorized.
one or more subjects.
Observation: For a payment to be overdue, the due date must be greater than
the date of the day.
Exercise No. - 52
There is a vector VEC(N) loaded with positive integer values, develop a
algorithm that separates the even values from VEC() into the vector PAR(M) and the odd ones from
VEC() in the IMP(P) vector, determine if PAR() and IMP() have the same amount of
elements and if so create a vector DIF() with the difference of the elements
from PAR() - IMP(), if the number of elements in PAR() and IMP() is different, create the
vector PRO() with the product of the elements until completing with the values of the vector
with fewer elements. Print all results.
Exercise No. - 53
Taking a vector A of N components, which is loaded with numerical values, create
from the same vector B that contains only the repeated values of A.
Example:
Vector A
4 1 0 2 1 2 0 0 1 2 3
Vector B created
1 0 2
Exercise No. - 54
Develop an algorithm that allows for the orderly insertion of a series into a vector.
values read sequentially, the vector is sorted from largest to smallest, that is
decreasingly. The values to be inserted must be introduced by finding the position
suitable for this, without altering the descending order, for this it is necessary to transport
all the elements, starting from the position found for insertion, from left to
right, removing the last element of the vector. In case the entered number already
there is ignore it and the process ends when the value zero is entered, which should not be
to be processed. All numbers are integers.
Example:
V(n)
55 44 33 22 11
Exercise No. - 55
Given the vectors VEC(n) and CONT(m) and generate a third vector RESU(p) with the
ordered correlating values. To do this, consider that the vectors CONT and VEC are
ordered and complete with integers. In case a number repeats in both
ignore vectors. All numbers are integers.
Example:
VEC(n)
12 14 23 24 28
CONT(m)
11 14 15 23 29
RESU(p)
11 12 15 24 28 29
At the end of the process, print the number of ignored values and the final vector.
Exercise - 56
There are N values, distributed as follows. Half of them are
integers and positive, the other half are integers and negative, the same values are
stored in a file, in the following order: first a positive element and
followed by another negative, in altered form, until all values are concluded. A
algorithm that stores values in a vector in the following way: in the first half
from the vector, all positive values and in the second half of the vector all values
negatives. Finally print the vector and the resulting difference from the sum of all
the positive values minus all the negative values.
The CUR(M) vector contains the book codes arranged in descending order.
a private library, which has three categories of books: Novels, Technical and
Stories. The code of each book consists of 7 digits with the following structure:
Code Description
Position 1-2 Book number
Position 3-5 Tipo de libro (101=Novela – 201=Tecnico y 301= Cuento)
Position 6-7 Version
Example: 1210101 breaking it down into 12 – 101 – 01 means Book No.12, novel
(101) and version 01
An algorithm is requested that decomposes the codes located in the vector CUR(M),
identify which category it belongs to and copy the codes to the vectors NOV(x), TEC(y)
the CUE(z), according to its category. It is known that there are 367 books, of which 130 are
novels, 79 technicians and the rest are stories.
Exercise No. - 57
The club '3 de febrero' wishes to determine the amount of commissions to be paid to each of
its vectors. To which it has contracted their programming services, requesting the
development of the algorithms that allow calculating the correct figures. It is necessary that the
Information related to sales is in a file with the following data:
NRO - Seller number. (There is more than one record for each seller and only have been
hired 5 salespeople).
VEN - value of the sale quota.
CUO - Number of installments.
SOC - Buyer Member Code
Area of the sold seat (1=Preferences, 2=Northern stalls, 3=Southern stalls)
4=Lower Stands, 5=Bleachers.
PAG - Payment method, with the following possible values (*=Cash sale – 1=Monthly
- 2 = Quarterly - 3 = Four-monthly.
POS - Number or position of the seat with the following possible values
Preferential
6=Member
10=Additional Family
The names of the vendors are loaded in the available vector VEN(5), for
process.
The last record has a value * in Nro and should not be processed
According to the sales amount of each seller, a commission value is granted.
according to the following criteria:
There are two types of commissions, one based on the area sold and the other based on position.
sold, the values are in the AR(ARE) and POSI(POS) tables.
If the sale is cash according to the AR(ARE) and POSI(POS) it corresponds to the
selling 100% of the sum of both vectors
The monthly sale corresponds to the AR(ARE) and POSI(POS).
seller 80% of the sum of both vectors.
If the sale is quarterly or quadrimestral according to AR(ARE) and POSI(POS), it
The seller is entitled to 70% of both vectors.
It is desired to know the total amount to be paid for each of the 5 vectors.
It is also desired to know the total amount of
Matrices
He who does not know which way to go
It reaches the sea, it must look for the river.
For my friend...
Plautus
Exercise No. - 1
The company 'RESURGIR DEL ESTE' wants to determine the amount of monthly salary to
to pay each of its employees. For which it has hired their services of
programming, requesting the development of algorithms that allow calculating the figures
correct. It is known that the information related to the employees is in a file
with the following data:
Nro - Employee number. (There is only one record for each employee)
Name – Employee's name.
Employee Area. (1=Management – 2=Administrative – 3=Technical – 4=Sales)
- 5 = General services).
ASI(31) – Daily assistance vector of the official with the following possible values. (*=
Holiday, non-working day, or not relevant for the month in question - 1 = Worked working day
- 2= Absentee workday with notice - 3= Absentee workday without notice.
ANT - Years of service as an employee of the company
CAR - Cargo within the company with the following values (1= President - 2=
Manager
2nd level technician
Support level 2
The last record has a value ** in Nro and should not be processed.
According to the seniority granted, starting from the first 5 years and for every 5 years of
seniority, an additional cumulative amount of 70,000Gs.
The employee's salary depends on their position and area, for which the table must be considered.
And the values indicated in the file.
The discounts are based on the number of absences incurred in the month and are
indicated in the vector, considering as absences to be deducted from the salary the
of absence 2 and 3 (absences with or without notice). The amounts to be deducted are listed in table B
wopA916.tmpMicrosoft_Excel_Spreadsheet1.xlsx
The table shows the daily discount values by charge and area.
Discount Table
CHARGES Area 1 2 3 4 5
1 50000 --
2 30000 20000 18000 18000 18000
3 10000 9000 9000 9000 9000
4 8000 7000 7000 7000 7000
5 -- -- xxx 5000 --
6 -- -- 5500 xxx --
7 -- -- -- 6000 --
8 -- -- -- 3000 --
9 xxx xxx xxx 3000 3000
10 2000 2000 2000 2000 2000
11 xxx xxx 6000 6000
TABLE B
For each employee, the requested values must be calculated and a list printed with
Number
net salary.
Exercise No. - 2
Develop an algorithm that allows, given a vector VEC(N) with loaded values,
find in a matrix MAT (M.N) the elements whose corresponding values by
the column should be closer to each VEC element. This is the value of the first element
of VEC corresponds to comparing it with all the elements of the first column of
MAT, the second from VEC with those from the second column, etc. Once these are detected
values for each print the difference found between the element of VEC and the
detected in each column of MAT.
All values are different, integers, and positive.
Exercise No. - 3
Develop an algorithm that locates and prints the values of the matrix MAT (M.N) and
their positions, when the values of the same are lower than those found in
the MEN matrix (M.N) comparing them symmetrically element by element, all the
Values of MAT () that do not meet this condition must be located in the matrix
SUP (L.P) and finally the sum of all elements of SUP () must be printed...
Exercise No. - 4
In a square matrix of order M (knowing that M > 2) filled with numerical data
an algorithm is required to calculate the sum and the average of the
elements that are not part of the borders and the main and secondary diagonals.
Exercise No. - 5
Considering the capability to generate reports from the company's listing system
RUBY S.A., develop an algorithm that allows controlling the entry and priority of the
requests for reports. For this, the system has a LIST matrix (M, 2) that
store the requests by order of priority: The goal of the algorithm is to read the
requests that come in the variables NRO and PRI where NRO represents the Number of
Request and PRI to the priority of the list. The priority values range from 1 to 5, where to
lower value higher priority; once a list is read, it should be placed in the vector of
an orderly manner so that those of highest priority are placed in the first
queues, in case of repetition the incoming order must be placed at the end of the orders of
equal priority. The algorithm concludes when the value read in NRO is less than zero.
In case a list is requested and LISTA has no empty spaces [LISTA
If (x.y)=0, a message indicating that "It is not possible to print the list" must be omitted.
Priority NUMBER
1 13
1 05
2 08
5 02
0 0
PRI NRO
1 7
2 12
It is not possible
Emit the
List
Exercise No. - 6
Develop an algorithm that allows the creation of the matrix MAT (12.5) containing
the data from the file of the amount of rainfall recorded in Ciudad del Este during the
previous year. This file contains the following data: Month (MM), Day (DD), amount of
Rainfall measured in mm^2. The matrix should total the data according to the following model:
Total days
Total effective rainfall is average Mayor
registered in rain in the monthly of precipitation
My the month month fallen rain registered
January 135 20 6.75 13
February 120 15 8 10
March 303 25 12,12 15
----- 230 20 11.5 --
December 120 15 8 13
Note: For the calculation of the average, only the effective rainy days should be considered.
Exercise No. - 7
The day's sales file of a gas station is organized as follows
form:
Maq.: machine code and con: liter counter.
There are 5 machines coded as follows: 1 and 2: gasoline machines
common. 3 and 4: diesel machines. 5 super gasoline machine.
There are 3 products with the following description and the following prices:
Description Price
=============
common nafta 900
Diesel 600
Super gasoline 1,200
For each sale of the day in each machine, there are two records: - The first one contains the
previous liter counter. - The second contains the current liter counter.
It is requested to create a pseudocode that allows calculating the total amount of guaraníes that has
collected from each machine. And the total for each product. At the end of each report, it
You must print the total amount to be collected.
To calculate the amount, you must first calculate the liters sold in that machine,
what will be the difference between the current counter and the previous counter. The result of this
calculation should be multiplied by the corresponding price depending on the product in question
treat.
Attention: for each machine there are two records, no more, no less and these will be
always consecutive. It is not necessary to check for errors in the file.
Example: If the file contains the following data:
Con. Mach.
=======
1 100
1 120
2 200
2 200
3 350
3 520
4 400
4 500
5 300
5 380
Exercise No. - 8
Develop an algorithm that removes null elements from the matrix MAT (M.N),
These elements are stored in the vector VEC (M), in cases where those
Values detected in the matrix must be replaced by '*'. Indicate the quantity,
summation and average of the valid values, as well as the row and column of the largest
null value detected. Print the results.
Exercise No. - 9
There is a FILE that contains the data and results of the tests conducted on
the medications of a pharmaceutical company, each record has the following format:
COD Medicine code number
PRU (5,5) Matrix of five rows and columns, with the test results
performed for each type of test. There are five possible types of tests and for each one
4 tests are carried out out of them. The rows indicate the types of tests and the columns the
Tests performed. The possible values range from 0 to 100. In the last column is
the minimum permitted values for each test are found.
Develop an algorithm that allows:
Calculate the difference between the average of the 4 tests and the values
minimum allowed for each test.
Determine whether the medication is approved or not, for which it is necessary to:
find the overall average of the differences obtained in point 1 and
verify that the result is equal to or greater than 70% to pass.
Exercise No. - 10
Develop an algorithm that locates and prints the values of the matrix MAT (M.N) and
their positions, when the values of the same are less than those found in
the matrix MEN(M.M) comparing them symmetrically element by element. All the
MAT() values that do not meet this condition must be accumulated and
finally, the result of this sum must be printed.
Exercise No. - 11
In the issuance of a sales list, a matrix is used - MAT(M.,N), with the
discount values corresponding to each region where sales of the item
Informatics is carried out. MAT contains the range applied in the MOVEN file with the
following data: SaleNo. Region (Row + Column of MAT. Example: Value 0301 = Row
3 Column 1), Gross Sales Amount, Net Sales Amount. It is necessary
develop an algorithm that allows verifying if the values of the file are correct,
To do this, it is enough to verify that: NET SALE = GROSS SALE - DISCOUNT.
If the values are correct, ignore. If, on the contrary, they are not accurate, record them.
in the ERROR file (with the following data: Sale Number, Region(), Gross Amount of
the Sale, Net Amount of the Sale), at the end of the process, print the quantity of
records with errors and what percentage of the total records in the Sales file this is
represent.
Exercise No. - 12
Develop a pseudocode algorithm that allows finding the average of
values of a square matrix of order M. Develop the algorithm and also print
the quantity and sum of the values found.
Exercise No. - 13
There is a square matrix MAT(M.M). M is an even value greater than 20, containing
positive integer numerical values: calculate the average of the values located in
the perimeter of the matrix and in the main and secondary diagonals.
Exercise No. - 14
Develop an algorithm that allows processing a matrix MAT(M.M) by printing it.
POSITION of the elements that are equal to the contents in the vector VEC(M): in
in case they are different, replace them with 0: finally print the sum and the
average of the different elements.
Exercise No. - 15
Determine in a matrix of order N the quantity and position of elements that are
equal to the elements of the vector NUM(M), as well as the result of the summation of
the elements of the matrix that are different from any element of the vector. Print
all the results.
Exercise No. - 16
Develop a pseudocode algorithm that allows finding in a matrix
square of order M loaded with positive integer values, the elements that are
repeat and replace them with *.
Exercise No. - 17
Develop an algorithm that allows finding the sum, quantity, and average of the
elements of a square matrix M(N.N) that belong to the triangle
superior (limited by the main diagonal, column N, and row 1)
Exercise No. - 18
There is a matrix MAT(M.M) where M is even. Develop an algorithm that sums the
elements of the odd row the elements of the next even row and store them in the row
by filling the odd column with zeros. Repeat the process for the entire matrix and
finally print it.
Exercise No. - 19
Develop an algorithm that allows finding the sum, quantity, and average of the
elements of a square matrix M(N.N) that belong to the triangle
inferior (limited by the main diagonal, row 1 and column N).
Exercise No. - 20
Develop an algorithm that allows identifying the values of the matrix MAT(M.N)
that meet the following conditions:
They should not exceed the maximum positive value of the vector VEC(P).
Knowing that the file is sorted by the employee's name, that there is only one
registration for each employee and that there is a record, which should not be processed,
with NULL value in the NROEMP field, indicating the end of the file. Develop a
algorithm that allows:
Determine in the auxiliary matrix MA1(5.12), for each area (field AREEMP)
from the company, what is the name (field NOMEMP) of the employee with the highest
number of absences with deduction (value2), in each month of the year.
Determine in the auxiliary matrix MA2(5.12), for each area (field AREEMP)
from the company, what is the category (field CATEMP) of the employee with the highest
net salary (SANE vector) for each month of the past year.
Exercise No. - 23
Knowing that there is a file with L records, each of them with a variable Z.
Develop an algorithm that allows creating a matrix in memory with the numbers from
file, such that the matrix has M rows and N columns. It is known that L = M*N. the matrix
It must be loaded row by row. Print the content of it.
Exercise No. - 24
Knowing that there is a matrix A of order M in memory, create an algorithm that
allow to find the sum of the elements that are in the main diagonal.
Exercise No. - 25
Knowing that there is a matrix A of order M in memory, create an algorithm that
allow to find the largest element of the upper triangle of a matrix A of order M.
Exercise No. - 26
Knowing that there is a matrix A of order M*N in memory, create an algorithm that
allow to swap the elements of the second row with the elements of row M.
Exercise No. - 27
Knowing that there is a matrix A of order M*N in memory, create an algorithm that
allow printing the elements of the matrix by traversing column by column.
Exercise No. - 28
Find the minimax solution of the columns of a matrix of order M*N. Minimax
it is the minimum element of the maximums of each column.
Exercise No. - 29
Given a matrix M, find the sum of the elements that are in the
secondary diagonal.
Exercise No. - 30
Given a matrix of order M*N, find the product of the elements different from 0.
each column and place them in a vector in the position that corresponds according to
the column in question: also count the zeros that appear by columns.
Print the created vector and the number of zeros per column.
Exercise No. - 31
A chain of warehouses for a product has 6 warehouses, each warehouse has 10
equal departments. The weekly sales of the chain of stores are stored
in a 6*10 matrix. A(i.j) denotes the weekly sales in the warehouse (i), in the
department (j).
Print:
The total weekly sales of each store.
Exercise No. - 32
A matrix M of order N is stored in memory. Create an algorithm that allows changing
the values of the first row with the last column and vice versa.
Exercise No. - 33
Given a matrix MAT of order M*N, create an algorithm that allows forming a vector.
with the elements located on the perimeter, which must be transferred to the vector, only
once.
Exercise No. - 34
Make the transfer of the main diagonal of matrix A from the diagonal
secondary of matrix B and print.
Exercise No. - 35
Build an algorithm that allows loading the elements of the triangle into a vector.
superior of the matrix MAT (M.M), where M is greater than 50, provided that the same
be positive and integers. The triangle is bounded by row and column 1 and the
main diagonal.
Exercise No. - 36
Given a matrix of order N, create an algorithm that first calculates the sum.
the main diagonal and the secondary diagonal, to then find the difference
among the summations.
Exercise No. - 37
Create an algorithm that allows you to complete the table presented below, for
which should read a file whose records contain the fields: Name - Salaries -
Sex.
The codes to be used are:
Sexo:1 = femenino – 2 = masculino
Salary: 1 = Salary <= G. 30,000
2 = Salary > G. 30,000 and Salary <= G. 50,000
3 = Salary > G. 50,000
Sex/Salary 1 2 3 Totals
Female
Male
Totals
Exercise No- 38
The result of a population census conducted has been recorded in a file.
country. For each registered person, the record has the following data:
Identification number - Zone code (less than 20 = capital. Between 21 and
50 = interior) - Age - sex (1 = male = female)
An algorithm must be created to print this table:
Capital Interior Totals
Age
H M TC H M IT TH TM
0-4
5-9
10-20
21- 45
45 or more
Totals
Exercise No - 39
The data of the loan movements from a financial institution over a year is
recorded on a disc. The records have the same format:
A loan number
Movement code (1 - Debit: 2 - Credit)
Credit line (1- Commercial: 2- Industrial: 3- Others)
Movement date
Amount
For each loan granted, a record was created (mobile code = 1)
For each payment made, a record was also created (mob. cod. = 2)
Knowing that the file is ordered by a loan number and within the
loan number by movement code. Create an algorithm that:
print the following table
Print a list of balances for each loan in the following format:
Loan number
Each loan can have: a single record (mobile code = 1). Or several records in which
In any case, the first will have mobile code = 1 and the others will have mobile code = 2.
Exercise No- 41
There is an 8 by 8 matrix, equivalent to a chess board. Read the position (row and
column) of a bishop, place an A in the entered position and in all positions in
the one that can move a P. Fill the rest of the matrix with zeros and print. Anticipate
that the bishop is at the extremes or corners (1.1 - 1.8 - etc.)
See examples for position (3.5)
P P
P P
A
P P
P P
P P
P
Exercise No- 42
Perform the previous exercise, but this time consider a horse (C) in place of the
the rook (A)
P P
P P
C
P P
P P
Exercise No– 43
Sort a matrix in ascending order, as indicated by the following example:
Original Ordered
9 4 0
3 8 5
1 6 7
0 1 3
4 5 6
7 8 9
Exercise No- 44
Read a matrix of dimension M * N. Create a vector in the following way:
The first element of the vector will be the smallest element of the first row of the matrix.
read, but greater than 0. The second element of the vector will be the smallest element.
from the second row of the read matrix, but that it is greater than 0 and so on.
Note: negative elements and zero are not taken into account for finding
the youngest.
Example:
1 2 3
0 7 9
3 -4 11
1
7
3
Vector created
Exercise No- 45
There is a square matrix of order N, two values I and J are read, which are the values
from the row and column corresponding to a particular element in the matrix. It is desired
print the result of the summation of the elements that surround it, as indicated
in the figure. If I or J come out 1 or N, issue a message clarifying the impossibility of
carry out the operation.
This process must be repeated M times.
Example:
I=3 J=2 …A(3.2)
Matrix A (4.4)
1.1 1.2 1.3 1.4
2.1 2.2 2.3 2.4
3.1 3.2 3.3 3.3
4.1 4.2 4.3 4.4
Exercise No- 47
Starting from a square matrix of order N. Create a vector by summing the elements of
the matrix as indicated in the figure.
a + e i m
b + f + j n
c g + k + o
d h l + p
Exercise No- 48
A checkers board is an 8 by 8 matrix, whose elements are K
(i,j); a 1 in k(i,j) represents the presence of a tile, while a 0 in K(i,j)
represents the absence of chips. Examine the board and store in N the number of chips
of the board.
Assume that the elements of the matrix only contain 1 or 0
Exercise No- 49
There is a file whose record contains data of the students of the faculty of
engineering, where there are 3 different types of degrees (civil - naval - electronic).
The format of each record is the following:oname
years that I take - sex.
The career field is coded in the following way:
Civil: 2 naval; 3 electronic
The last record has 9 in sex.
It is desired to print the following table:
Exercise No- 50
There is data on the employees of a factory:
No de empleado – nombre- edad- sexo (0 = Hombres, 1 = mujeres)
The following frequency table is to be created.
Exercise No– 53
Prepare a flow algorithm to read a matrix of order M * N, and determine the
the maximum, the minimum, the range, and the average of each column by column.
Note: Range = Maximum - Minimum.
It is also desired to calculate the average of all the elements of the matrix. Print all the
found values.
Exercise No - 54
There is a file with the following information:
Name
Sexo: 1 – Mujeres: 2-Hombres
Tipos de actividad: 1-dentro: 2-fuera: 3-dentro y fuera.
Create the flow algorithm to obtain the following frequency table:
Remuneration
Inside
Outside
Total
Exercise No– 55
There is a square matrix A of order N, which is divided into 2 triangles by the
main diagonal. Create a vector where the i-th element is equal to the average of
the elements of the upper triangle found in column i. The triangle
superior is made up of all the elements of the matrix that are above the
main diagonal (including itself)
Exercise No- 56
Flatten a matrix to a vector, by rows (dimension M * N)
Unroll a matrix into a vector, by columns (dimension M * N)
Exercise No- 57
Analyze whether two read matrices are equal, the dimensions are: A (m * N) and B (P * Q).
Exercise No- 58
Read a matrix A (10 * 10) and two integers M and N less than or equal to 10.
fill the row M and column N of the matrix with zeros.
Exercise No– 59
Read a matrix A of order M * N and a scalar K, and create and print the matrix of the
next way.
C (i.J9 = K * A (i, j)
Exercise No- 60
There is a file of the members of a sports club.
Among the data are:
Name
Sexo: 1- masculino. 2-Femenino
Marital status: [Link]... 3 = single
Sport: to choose from 9 possible options.
The following table is desired to be printed:
Exercise No- 61
Sum all the elements of a matrix read A of order M * N and find the average
among all its elements.
Exercise No– 62
Read a matrix B (M * N) and subtract the minimum element from all the elements.
matrix
Exercise No - 63
Read a matrix A (M * N) and create two vectors F of dimension M and C of dimension
N, where each:
F (i) = sum of the elements of row i
C (i) = sum of the elements of column i.
Exercise No- 64
Read a 10 * 10 matrix. Sum each odd column with the next even one.
put the result in the odd column, filling the even column with zeros. Repeat the
process for the entire matrix.
Exercise No- 65
Read a matrix (A (M * N) and find the matrix B (M * N), such that:
B = transpose of A. where b(i,j) = a(j,i)
If the matrix is square (M * N), transpose in the same matrix.
Exercise No- 66
Vectorize a matrix when P (size of the vector) and M * N are known.
(matrix size) and it holds that P = M * N.
Exercise No- 67
There is a file of the professors of the Polytechnical Faculty. For each professor, there is
a record they have: No of professor - career in which he/she teaches - professional degree -
course in which he teaches.
Codes:
Of races:
Computing
Production calculator
Higher technician in electricity.
Electronics
Of professional degree:
University graduate.
Without a university degree
Create an algorithm to produce the following table:
Professional Degree Course
Race Total Untitled 1 2 3 4
Exercise No - 68
Print a matrix that corresponds to a specific month of the calendar of a year
specific.
The first column corresponds to Sunday, the second to Monday, and so on.
successively.
INTRODUCE: specific month, day that falls on the 1st of January of that specific year.
Example:
Specific date: July 7
specific year: 1986
January 1, 1986:4 (Wednesday)
Exercise No- 69
Read a square matrix of dimension N, sum the elements (indicated by the letter
o), located in the model indicated in the figure.
Clarification: a square matrix is divided into four triangles by the diagonal
primary and secondary, as shown in the figure.
0 - - - - - 0
0 0 - - - 0 -
0 0 0 - 0 -
0 0 0 0 - -
0 0 0 - 0 -
0 0 - - - 0 -
0 - - - - 0
Exercise No- 70
Write an algorithm that allows taking the data from the matrix MAT (M.N) that is available.
loaded with numerical values, provided that they are less than 1 or
greater than 50, and transfer them to the vector VEC (P) the data less than 1 in the positions
odd numbers and the data greater than 50 in the even positions of the vector.
Exercise No- 71
There is a matrix of order M (M is odd and greater than or equal to 7). Create the algorithm.
that allows displaying a diamond, like the one in the figure, with the elements that
they form the surface of it.
1
1 1 1
1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1
1 1 1
1
Exercise No– 72
The development of an algorithm is requested to calculate the interest sums that
overdue customers of Financiera NEGRURA S.A. must pay, who have the data
related to their clients in a file with the following configuration:
NRO Customer number.
CAT Current customer category code. (1 = Preferred - 2 = Superior - 3
Special - 4=
Excellent - 5 = normal
EMP Minimum = 1 - Maximum = 8
NAME client_name
SIT(4) Situación de cada préstamo( 1 = Moroso -2 = Al dia)
PRE(4) vector with active loan category code of the client.
PAT(4) vector with amounts of payments made on each loan, up to date
It also has two matrices loaded with values whose indices match
the data contained in the records
Example: The table shows loan amounts by company and category.
Loan amount table
Level Category 1 2 3 4 5
1 8,500,000 5,700,000 2,500,000 2,200,000 1,000,000
2 9,500,000 1,800,000 2,800,000 2,800,000 1,800,000
3 10,300,000 1,100,000 3,100,000 3,100,000 2,100,000
4 10,000,000 1,500,000 3,700,000 3,700,000 2,700,000
5 11,200,000 1,780,000 3,900,000 4,200,000 3,500,000
6 11,650,000 1,800,000 4,100,000 4,300,000 3,650,000
7 11,950,000 1,980,000 4,490,000 4,600,000 3,890,000
8 12,150,000 2,250,000 4,780,000 5,300,000 4,000,000
Matrix A
Interest table
Level Category 1 2 3 4 5
1 5 6 7 8 9
2 11 13 15 17 19
3 12 14 16 18 29
4 23 25 27 20 31
5 34 36 37 38 39
6 24 26 28 30 32
7 41 42 45 46 47
8 42 44 48 49 50
Matrix B
Using the data from the file and the indicated matrices, process the following calculations.
in an algorithm and print the data indicated below:
The client can have up to 4 simultaneous loans whose amounts are in the
matrix A according to the EMP and PRE indices ( ). Calculate the total amount of the
loans granted to the client
The payments whose amounts are in PAT( ), allow establishing the balance of each
loan
If the customer is late in payment, apply a fine according to the values of matrix B.
indices.