Sum of 100 odd numbers using While loop
declare
n number;
endvalue number;
sum1 number default 0;
begin
endvalue:=&endvalue;
n:=1;
while(n<endvalue)
loop
sum1:=sum1+n;
n:=n+2;
end loop;
dbms_output.put_line('Sum of Odd numbers between 1 and '|| endvalue ||' is '||sum1);
end;
/
Enter value for endvalue: 30
old endvalue:=&endvalue;
new endvalue:=30;
Sum of Odd numbers between 1 and 30 is 225
declare
n number;
endvalue number;
sum1 number default 0;
begin
endvalue:=&endvalue;
n:=1;
while(n<endvalue)
loop
sum1:=sum1+n;
n:=n+2;
end loop;
dbms_output.put_line('Sum of Odd numbers between 1 and '|| endvalue ||' is '||sum1);
end;
/
Enter value for endvalue: 30
old endvalue:=&endvalue;
new endvalue:=30;
Sum of Odd numbers between 1 and 30 is 225
No comments:
Post a Comment