0% found this document useful (0 votes)
12 views3 pages

LAB4

The document contains 7 programming exercises in Vietnamese that demonstrate if/elseif/else statements, switch statements, functions, for loops, while loops, and checking for prime numbers. The exercises get progressively more complex and cover a range of programming concepts.

Uploaded by

Duy Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

LAB4

The document contains 7 programming exercises in Vietnamese that demonstrate if/elseif/else statements, switch statements, functions, for loops, while loops, and checking for prime numbers. The exercises get progressively more complex and cover a range of programming concepts.

Uploaded by

Duy Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB4

E1:
clear all;
clc;
n=input('nhap n= ');
if n==0;
disp('khong');
elseif n==1;
disp('mot');
elseif n==2
disp('hai')
elseif n==3
disp('ba')
end
E2:
clear all;
clc;
n=input(' nhap n= ');
switch n;
case 0;
disp ('khong');
case 1;
disp('mot');
case 2;
disp('hai');
case 3;
disp('ba');
case 4;
disp
E3:
clear alll;
clc;
n=input('nhap n= ');
tram=fix(n/100);
chuc=fix(mod(n,100)/10);
dvi=mod(n,10);
doc_so(tram);
doc_so(chuc);
doc_so(dvi);

function doc_so(n)
%chuong trinh doc so
if n==0
fprintf('khong ')
elseif n==1
fprintf('mot ')
elseif n==2
fprintf('hai ')
elseif n==3
fprintf('ba ')
elseif n==4
fprintf('bon ')
elseif n==5
fprintf('nam ')
elseif n==6
fprintf('sau ')
elseif n==7
fprintf('bay ')
elseif n==8
fprintf('tam ')
elseif n==9
fprintf('chin ')
end
E4:
clear all;
clc;
x=0.75;
S=0;
for n=0:19
S=S+(((-1)^n)*(x^(2*n)));
end
S
E5:
clear all
clc
x=pi/6;
S=0;
n=0;
while (((x^(2*n))+1)/((2*n)+1))>0,0001
S=S+(((-1)^n))*((((x^(2*n))+1)/((2*n)+1)));
n=n+1;
end
S
E6:
clear all;
clc;
a=input('nhap a= ');
b=input('nhap b= ');
c=input('nhap c= ');
if (a>0)&&(b>0)&&(c>0)&&(a+b>c)&&(a+c>b)&&(b+c>a)
if (a==b)||(a==c)||(b==c)
if (a==b)&&(b==c)
disp('tam giac deu');
elseif((a^2)+(b^2)==(c^2))||((a^2)+(c^2)==(b^2))||((b^2)+
(c^2)==(a^2));
disp('tam giac vuong can');
else
disp('tam gia can');
end
elseif((a^2)+(b^2)==(c^2))||((a^2)+(c^2)==(b^2))||((b^2)+(c^2)==(a^2));
disp('tam giac vuong');
end
else3
disp('khong phai tam giac');
end
E7:
clear all;
clc;
n=input('nhap n= ');
while mod(n,1)~=0||n<=0;
n=input('nhap lai n= ');
end
%xet so nguyen to
for k=2:n;
if mod(n,k)==0;
break;
end
end
if n==k;
disp('la so nguyen to');
else
disp('khong phai la so nguyen to');
end

You might also like