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

Tema Pentru Acasă

The document contains 4 programs (P1, P2, P3, P4) that calculate the sum and product of integers from 1 to n, with some integers excluded based on their modulus. It also includes a supplemental program to calculate the greatest common divisor and least common multiple of two integers.
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)
13 views

Tema Pentru Acasă

The document contains 4 programs (P1, P2, P3, P4) that calculate the sum and product of integers from 1 to n, with some integers excluded based on their modulus. It also includes a supplemental program to calculate the greatest common divisor and least common multiple of two integers.
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/ 2

Tema pentru acasă

a) Program P1; b) Program P2;


var i, n, s, p: integer; var i, s,n, p: integer;
begin begin
writeln (‘n=’); readln (n); writeln (‘n=’); readln(n);
s:=0; s:=0;
p:=1; p:=1;
for i:=1 to n do for i:=2 to n do
begin begin
if (i mod 2 <>0) then s:=s+i; if (i mod 2=0) then s:=s+i;
p:=p*i; p:=p*i;
writeln (‘s=’,s); writeln (‘p=’,p); writeln (‘s=’,s); writeln (‘p=’,p);
end; end;
readln; readln;
end. end.

c) Program P3; d) Program P4;


var i, n, s, p: integer; var i, n, s, p: integer;
begin begin
writeln (‘n=’); readln (n); writeln (‘n=’); readln (n);
s:=0; s:=0;
p:=1; p:=1;
for i:=3 to n do for i:=4 to n do
begin begin
if (i mod 3=0) then s:=s+i; if (i mod 4=0) then s:=s+i;
p:=p*i; p:=p*i;
writeln (‘s=’,s); writeln (‘p=’,p); writeln (‘s=,s); writeln (‘p=’,p);
end; end;
readln; readln;
end. end.
Suplimentar:
Program cmmdc_cmmmc;
var n1, n2: integer;
function cmmdc (n1, n2: integer): integer;
begin
while n1<>n2 do
if n1>n2 then n1:=n1-n2 else n2:=n2-n1;
cmmdc:=n1;
end;
function cmmmc (n1,n2: integer): integer;
begin
cmmmc:=n1*n2 div cmmdc (n1,n2);
end;
begin
writeln (‘Primul numar n1:’); readln (n1);
writeln (‘Al doilea numar n2:’); readln (n2);
writeln (‘Cel mai mare divizor comun este:’);
writeln ( cmmdc( n1, n2) );
writeln (‘Cel mai mic multiplu comun este:’);
writeln (cmmmc( n1, n2) );
readln;
end.

You might also like