0% found this document useful (0 votes)
18 views2 pages

Info 2

The document contains 4 programs labeled P1 through P4. Each program prompts the user to input a number n, initializes variables s and p, uses a while loop from 1 to n, performs conditional logic on i based on its modulus, updates s and p, prints the results, and ends. P1 sums odd numbers and multiplies all. P2 sums even numbers and multiplies all. P3 sums numbers divisible by 3 and multiplies all. P4 sums numbers divisible by 4 and multiplies all.
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)
18 views2 pages

Info 2

The document contains 4 programs labeled P1 through P4. Each program prompts the user to input a number n, initializes variables s and p, uses a while loop from 1 to n, performs conditional logic on i based on its modulus, updates s and p, prints the results, and ends. P1 sums odd numbers and multiplies all. P2 sums even numbers and multiplies all. P3 sums numbers divisible by 3 and multiplies all. P4 sums numbers divisible by 4 and multiplies all.
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;
while i<=n do while i<=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;
while i<=n do while i<=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.

You might also like