Showing posts with label PL/SQL. Show all posts
Showing posts with label PL/SQL. Show all posts

Friday, December 27, 2019

Fibonacci - PL/SQL

Program:

declare
i number;
c number;
n number;
a number;
b number;
begin
for i in 1..n
loop
c:=a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end

Output:

Enter valur for n; 5
0
1
1
2
3

Palindrome - PL/SQL

Program:

declare
len number;
a integer;
str1 varchar(10):='&str1';
str2 varchar(10);
begin
len:=length(str1);
a:=len;
for i in 1..a
loop
str2:=str2||substr(str1,len,1);
len:=len-1;
end loop;
if(str1=str2) then
dbms_output,put_line(str1 ||' is a palindrome');
else
dbms_output,put_line(str1 ||' not a palindrome');
end if;
end

Output1:

Enter value for str1; liril
liril is a palindrome

Output2;

Enter value for str1; faith
faith not a palindrome


Factorial Of A Number - PL/SQL

Program:

declare
f number:=1;
i number;
n number:=&n;
begin
for i in 1..n
loop
f:=f*i;
end loop;
dbms_output.put_line('The factorial of a given no is:'||f);
end;

Output:
Enter alue for n: 6
The factorial of a given n is: 720

Addition Of Two Numbers - PL/SQL

Program:

declare
x integer;
y integer;
z integer;
begin
x:=&x;
y:=&y;
z:=x+y;
dbms_output.put_line('The sum of two number is ='||z);
end;



Output:

Enter value for x: 9
Enter value for y: 9
The sum of two number is =18


Saturday, April 14, 2018

Sample Program – Python List



pythonList.py

subjects = ['Maths','Physics','Chemistry']
marks = [190,178,185]

print("*****Score Details*****")
print(subjects[0],':',marks[0])
print(subjects[1],':',marks[1])
print(subjects[2],':',marks[2])

list_1,list_2 = [1,2,3,4],[1,7,8]

print('\nList 1: ',list_1,'\nList count: ',len(list_1),'\nMax Value: ',max(list_1),'\nMin Value: ',min(list_1))
print('List 2: ',list_2 )

#inserting into list_2
list_2.append(10)
print('List 2 after append: ',list_2 )

#extending list_2 with sequence of values
list_2.extend([9,11,12])
print('List 2 after extend: ',list_2 )

#reversing the list
list_2.reverse()
print("Reverse list: ",list_2)

#finding the index of object in list
print('Index of 9 in list 2: ',list_2.index(9))

#sorting the list desc
list_2.sort(reverse= True)
print("List after sorting: ",list_2)

#removing object from the list
list_2.remove(11)
print("List after removing 11: ",list_2)

#updating object in the list
list_2[0]=13
print("List after updating index 0 with 13: ",list_2)

#displaying a range from a list
print("List with first 5 values: ",list_2[0:5])
print("List from 2nd index: ",list_2[1:])



output:
*****Score Details*****
Maths : 190
Physics : 178
Chemistry : 185

List 1:  [1, 2, 3, 4]
List count:  4
Max Value:  4
Min Value:  1
List 2:  [1, 7, 8]
List 2 after append:  [1, 7, 8, 10]
List 2 after extend:  [1, 7, 8, 10, 9, 11, 12]
Reverse list:  [12, 11, 9, 10, 8, 7, 1]
Index of 9 in list 2:  2
List after sorting:  [12, 11, 10, 9, 8, 7, 1]
List after removing 11:  [12, 10, 9, 8, 7, 1]
List after updating index 0 with 13:  [13, 10, 9, 8, 7, 1]
List with first 5 values:  [13, 10, 9, 8, 7]
List from 2nd index:  [10, 9, 8, 7, 1]