Practice 1 Exercises in Matlab
Practice 1 Exercises in Matlab
fordescuento=0.85
A student wants to know what their final grade will be in the Algorithms subject. That grade
is composed of the following percentages:
55% of the average of your three partial grades.
30% of the final exam grade.
15% of the final project grade.
A teacher wants to know what percentage of men and what percentage of women there are.
in a group of students.
%program that calculates the percentage
N=input('Enter the total number of students: ');
H=input ('Enter the total number of students: ');
M=input ('Enter the total number of students: ');
T=H+M
if T == N
PM=M/N*100;
PH=H/N*100;
fprintf ('Percentage of men = %1.2f %% ',PH);
Percentage of women = %1.2f %%
else
The entered values are incorrect... Please try again
again
end
A man wants to know how much money is generated from the concept of
interest on the amount you have invested in the bank.
He will decide to reinvest the interests as long as these
exceed $7000, and in that case wants to know how much money he will have
finally in his/her account.
2. Fromdetermine if a student passes or fails a course, knowing that they will pass if their average
three grades are greater than or equal to 70; fail otherwise.
weekly hours
the hours worked during the week are:
%d',weeklyhours);
if weekly hours > 40
16*40+20*(horassemanales-40);
fprintf('the weekly salary is: %d', weeklypay);
else if weekly hours < 40
weekly payment = 16 * weekly hours;
the weekly salary is: %d
end
end
6.Create an algorithm that calculates the total to be paid for the purchase of
shirts. If three or more shirts are purchased, a 20% discount applies.
about the total of the purchase and if there are less than three shirts a discount
of 10%
totalformat=costperpiece*numberofpieces;
if montototal > 500000;
cantidadinv = montototal * 0.55;
loan=totalamount*0.30;
montototal * 0.15;
elsemontototal<500000;
montototal * 0.70;
totalAmount * 0.30;
0
end
interest = 0.20 * credit;
end
the total amount is:%d
the money that the company invested was: %d
The loan requested at the bank was: %d
the credit to the manufacturer is:%d
the interest generated from the credit is: %d
2. Calculate the profit that a worker receives in the annual profit sharing if this is assigned to them.
as a percentage of their monthly salary that depends on their seniority in the company according to
with the following table:
Time Utility
Less than 1 year 5% of the salary
1 year or more and less than 2 years 7% of the salary
2 years or more and less than 5 years 10% of the salary
5 years or more and less than 10 years 15% of the salary
10 years or more 20% of the salary
ifcolordebola==1;
moneytopay=totalpurchase-0;
else
ifcolordebola==2;
totaldecompra - totaldecompra * 0.10;
else
ifcolordebola==3;
totalpurchase - totalpurchase * 0.25;
else
amounttodipay = totalpurchase - totalpurchase;
end
end
end
4. The IMSS needs to classify the individuals who will retire in the
year 1997. There are three types of retirements: by age, by
youth seniority and adult seniority. The people assigned
To retire by age, they must be 60 years or older and have a seniority.
in their employment of less than 25 years. The people assigned to the
young retirement due to seniority must be under 60 years old and a
seniority in their employment of 25 years or more. The people assigned
to retirement for older tenure must be 60 years old or more and
a seniority in their job of 25 years or more.
Determine what type of retirement a person will be assigned to.
Cycles
n=0;
p=0;
[a b c d e f g h i j]
ifm>0
p = p + 1;
else
n=n+1;
end
end
positive values %d
3. Read 20 numbers and print how many there are positives, how many
negatives and how many neutrals.
a = input('please enter your number: ');
b= input('enter your number: ');
c= input('enter your number: ');
d = input('enter your number: ');
e= input('enter your number: ');
f = input('enter your number: ');
g = input('enter your number: ');
h= input('enter your number: ');
i= input('enter your number: ');
j = input('please enter your number: ');
k= input('enter your number: ');
l = input('enter your number: ');
m= input('enter your number: ');
n = input('enter your number: ');
o = input('enter your number: ');
p = input('enter your number: ');
q= input('enter your number: ');
r = input('enter your number: ');
s= input('enter your number: ');
t= input('enter your number: ');
0
negativo=0;
positivo=0;
forx = [a b c d e f g h i j k l m n o p q r s t]
if x > 0
positive = positive + 1;
elseif x < 0
negative=negative+1;
elsex=0;
neutro=neutro+1;
end
end
fprintf('positive values %d\n',positive)
negative values %d
fprintf('neutral values %d\n', neutro)
program that calculates the average grade and the lowest one of the group
clc
Enter the grades as a vector:
A=mean(C);
B=min(C);
The minimum grade is = %1.2f
The average grade is = %1.2f
forH=1:23
forM=1:59
for S=1:59
end
end
end
%d hours %d min %d sec.
Problems
clc
enter the value of the pressure
enter the temperature value
input('enter the value of the volume');
formasa=pressure*volume/(0.37*(temperature+460));
the value of the mass is %d
end
2. Determine the weekly amount of money that each one will receive.
The n workers of a company. It is known that when the hours that
I work as a laborer exceeding 40, the rest becomes overtime hours.
overtime that is paid double the normal hourly rate, when it does not exceed
from 8; when overtime exceeds 8, the first ones are paid
8 times double what is paid for a normal hour and the rest to the
triple.
3. On a farm, some information is required to determine the selling price for each.
kilo of egg. It is important to determine the average quality of the hens that are present in the
farm. The quality of each hen is obtained according to the formula:
Quality = weight of the hen * height of the hen
Number of eggs laid
Finally, to set the price of a kilogram of eggs, the following table is used as a basis:
TOTAL QUALITY PRICE PRICE PER KILO OF EGG
Greater than or equal to 15 1.2 * average quality
Greater than 8 and less than 15 1.00 * average quality
Less than or equal to 8 0.80 * average quality
%program that indicates the price according to the quality of the hen
clc
w=input('Enter the weight of the hen (kg): ');
h=input('Enter the height of the chicken (cm): ');
n=input('Enter the number of eggs laid:');
c = w * h / n;
ifw<=0 | h<=0 | n<=0
The entered values are incorrect...Please try again.
again
else
ifc>=15
p=1.2*c;
The price per kilo of eggs is =$ %1.2f
elseif c > 8 and c < 15
p=1.0*c;
The price per kilo of eggs is = $ %1.2f
elseifc<=8
p=0.8*c;
The price per kilo of eggs is =$ %1.2f
end
end
clc
%case for 10 representatives
a = input('enter your number:');
b = input('enter your number:');
c = input('enter your number:');
d = input('enter your number:');
e = input('enter your number:');
f = input('enter your number:');
g = input('enter your number:');
h = input('enter your number:');
i = input('enter your number:');
j = input('enter your number:');
f=1;
c=-1;
a=0;
form = [a b c d e f g h i j]
ifm>0
f = f + 1;
else
ifm < 0
c=c+1;
else
a=a+1;
end
end
end
The percentage of those in favor is %d
fprintf('the percentage of those who are against %d\n',c*100/10)
the percentage of those who abstain is %d
percentage_of_education_level_of_the_surveyed_people
clc
n=input('Enter the total number of surveyed people: ');
Enter the number of people with primary education:
');
s=input('Enter the number of people with education at the level
secondary
t=input('Enter the number of people with technical degrees: ');
u=input('Enter the number of people with professional degrees: ');
ps=input('Enter the number of people with postgraduate studies: ');
ifn==p+s+t+u+ps
pp = p/n * 100;
ps=s/n*100;
pt=t/n*100;
pu = u/n * 100;
pps=ps/n*100;
RESULTS :
Primary education studies = %1.2f %%
fprintf('Secondary education studies = %1.2f %% \n', ps);
Technical careers = %1.2f %%
Professional studies= %1.2f %%
Postgraduate studies = %1.2f %%
else
Error entering the data... Please try again.
end
A polling station chief wants to determine how many people from each
one of the sections that make up your area attends on the day of the
Voting. The sections are: north, south, and center. Also
wants to determine which is the section with the highest number of
voters.
enter the number of people in the south section
northern_section=input('enter the number of people in the section
north
sectionCenter = input('enter the number of people in the section
center
aprobado=0;
reprobado=0;
The provided text does not contain a translatable phrase.
F G H I J K L M N O P Q R S T U V W X
if Y < 70
failed = failed + 1;
else Y>70
approved = approved + 1;
end
end
fprintf('the percentage of failures is: %d', failed*100/50);
c=[];
fore=1:n
Enter the student code:
v=[];
c=[c l];
for j = 1 to b
m=input('Enter the grade (from 0 to 20): ');
v=[v m];
y=mean(v);
end
r=[r y];
end
[x,p]=max(r);
u=c(p);
display('The average value is')
display(x)
The student with the best average is
display(u)
12. The teacher of a subject wants to know the number of his students.
that do not have the right to the leveling exam. Design an algorithm
that reads the grades obtained in the 5 units by each one
of the 40 students and write down the number of them who do not have the right
to the leveling exam.
program that calculates the average grade and the lowest one of the group
clc
The columns represent each student;
it would be 40
disp('The rows represent the grades'); %for the case it would be 5
rows(grades)
A=input('Enter matrix: ');
B=mean(A);
N=B(B<=10);
L=length(N);
The students who need to take the leveling exam are =
%1.0f