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

Sum

The document contains code snippets for three questions that involve looping through numbers and performing calculations or conditional checks on the numbers. The first question sums the digits of a number by looping through each digit. The second question does the same but in reverse order. The third question loops from one number to another, checking if each number is odd or even and outputting the label.

Uploaded by

Syaz Niey
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Sum

The document contains code snippets for three questions that involve looping through numbers and performing calculations or conditional checks on the numbers. The first question sums the digits of a number by looping through each digit. The second question does the same but in reverse order. The third question loops from one number to another, checking if each number is odd or even and outputting the label.

Uploaded by

Syaz Niey
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Question 1

declare
no1 number;
saiz number;
a varchar2(10);
i number;
sum1 number := 0;
BEGIN
no1:=&no_1;
saiz:=length(no1);
for i IN 1.. saiz loop
a := substr(no1,i,1);
sum1 := sum1 + a;
dbms_output.put(a||' ' );
end loop;
dbms_output.put_line ('Berjaya!!');
dbms_output.put_line ('Jumlah : '||sum1);
end;
___________________________________________
Question 2
declare
no1 number;
saiz number;
a varchar2(10);
i number;
sum1 number := 0;
BEGIN
no1:=&no_1;
saiz:=length(no1);
for i IN reverse 1.. saiz loop
a := substr(no1,i,1);
sum1 := sum1 + a;
dbms_output.put(a||' ' );
end loop;
dbms_output.put_line ('Berjaya!!');
end;
__________________________________
Question 5
declare
no1 number;
i number;
no2 number;
BEGIN
no1:=&no_1;
no2:=&no_2;
for i IN no1 .. no2 loop
if mod(i,2)=1 then
dbms_output.put_line('Ganjil : '||i);
else
dbms_output.put_line('Genap : '||i);

end if;
end loop;
end;

You might also like