Saturday, February 22, 2014

Advance Pattern Printing


1 -----------------------------------------


* * * * * * * * * *
*                   *
*                   *          
*                   *
* * * * * * * * * *


DECLARE
SPACE VARCHAR2(1):=' ';
STAR VARCHAR2(1):= '*';
S_PRINT VARCHAR2(50);
P_SPACE VARCHAR2(50);
BEGIN
FOR I IN 1..&A
LOOP
    S_PRINT:= S_PRINT||STAR||SPACE;
END LOOP;
DBMS_OUTPUT.PUT_LINE(S_PRINT);
FOR J IN 1..&&A/3
LOOP
    P_SPACE:= NULL;
    FOR I IN 1..&&A*2-3
    LOOP
        P_SPACE:= P_SPACE||SPACE;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('*'||P_SPACE||'*');
END LOOP;
DBMS_OUTPUT.PUT_LINE(S_PRINT);
END;


2 ------------------------------------

* * * * * *
*          *
*          *
*          *
*          *
* * * * * *


DECLARE
SPACE VARCHAR2(1):=' ';
STAR VARCHAR2(1):= '*';
S_PRINT VARCHAR2(50);
P_SPACE VARCHAR2(50);
BEGIN
FOR I IN 1..&A
LOOP
    S_PRINT:= S_PRINT||STAR||SPACE;
END LOOP;
DBMS_OUTPUT.PUT_LINE(S_PRINT);
FOR J IN 1..&&A-2
LOOP
    P_SPACE:= NULL;
    FOR I IN 1..&&A*2-3
    LOOP
        P_SPACE:= P_SPACE||SPACE;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('*'||P_SPACE||'*');
END LOOP;
DBMS_OUTPUT.PUT_LINE(S_PRINT);
END;

3 --------------------------------------


* * * * * * * * * *
*                   *
* * * * * * * * * *
*                   *
* * * * * * * * * *
*                   *
* * * * * * * * * *
*
*
*
*
*
*
*
*
**
****
******

DECLARE
SPACE VARCHAR2(1):=' ';
STAR VARCHAR2(1):= '*';
S_PRINT VARCHAR2(50);
P_SPACE VARCHAR2(50);
S_STAR VARCHAR2(20);
BEGIN
FOR I IN 1..17
LOOP
    P_SPACE:= P_SPACE||SPACE;
END LOOP;
FOR J IN 1..7
LOOP
    S_PRINT:= NULL;
    FOR I IN 1..10
    LOOP
        S_PRINT:= S_PRINT||STAR||SPACE;
    END LOOP;
    IF MOD(J,2)!=0
    THEN
        DBMS_OUTPUT.PUT_LINE(S_PRINT);
    ELSE   
        DBMS_OUTPUT.PUT_LINE(STAR||P_SPACE||STAR);
    END IF;
END LOOP;
FOR I IN 1..8
LOOP
    DBMS_OUTPUT.PUT_LINE(STAR);
END LOOP;
FOR I IN 1..3
LOOP
    S_STAR:= S_STAR||STAR||STAR;
    DBMS_OUTPUT.PUT_LINE(S_STAR);
END LOOP;   
END;

No comments:

Post a Comment