Wednesday, 17 October 2012
CLS
'PROGRAM TO PRODUCE THE COFACTOR, ADJOINT AND INVERSE OF ANY 3 BY 3 MATRIX
'THIS VERSION USES THE READ/DATA STATEMENT
'INPUT THE DIMENSIONS OF THE MATRIX IN THE DATA STATEMENT BELOW
DATA 3,3
READ M, N
DIM A(M, N)
DIM C(M, N)
DIM INV(M, N)
'INPUT THE ELEMENTS OF THE ORIGINAL MATRIX
'IN THE ORDER OF TOP TO BOTTOM AND LEFT TO RIGHT
DATA 2,1,2,-4,3,1,2,3,5,1,2,3,4,5,6,7,8 'TESTING ELEMENTS
FOR I = 1 TO M
FOR J = 1 TO N
READ A(I, J)
NEXT
NEXT
PRINT " THE ORIGINAL MATRIX A"
FOR I = 1 TO M
FOR J = 1 TO N
PRINT USING "##"; A(I, J);
PRINT " ";
NEXT
NEXT
'THE COFACTOR MATRIX
C(1, 1) = (A(2, 2) * A(3, 3) - A(2, 3) * A(3, 2))
C(1, 2) = -(A(2, 1) * A(3, 3) - A(2, 3) * A(3, 1))
C(1, 3) = (A(2, 1) * A(3, 2) - A(2, 2) * A(3, 1))
C(2, 1) = -(A(1, 2) * A(3, 3) - A(1, 3) * A(3, 2))
C(2, 2) = (A(1, 1) * A(3, 3) - A(1, 3) * A(3, 1))
C(2, 3) = -(A(1, 1) * A(3, 2) - A(1, 2) * A(3, 1))
C(3, 1) = (A(1, 2) * A(2, 3) - A(1, 3) * A(2, 2))
C(3, 2) = -(A(1, 1) * A(2, 3) - A(1, 3) * A(2, 1))
C(3, 3) = (A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1))
PRINT "THE COFACTOR MATRIX"
FOR I = 1 TO M
FOR J = 1 TO N
PRINT USING "###"; C(I, J);
PRINT " ";
NEXT
NEXT
PRINT " THE TRANSPOSE OF THE COFACTOR (ADJOINT OF THE MATRIX, A)"
FOR I = 1 TO N
FOR J = 1 TO M
PRINT USING "###"; C(J, I);
PRINT " ";
NEXT
NEXT
PRINT "THE DETERMINANT OF A IS ";
D = A(1, 1) * A(2, 2) * A(3, 3) + A(1, 2) * A(2, 3) * A(3, 1) + A(1, 3) * A(2, 1) * A(3, 2) - A(3, 1) * A(2, 2) * A(1, 3) - A(3, 2) * A(2, 3) * A(1, 1) - A(3, 3) * A(2, 1) * A(1, 2)
PRINT D
IF D <> 0 THEN
GOTO 50
ELSE GOTO 100
END IF
50 PRINT "THE INVERSE OF A IS"
FOR I = 1 TO N
FOR J = 1 TO M
INV(I, J) = C(J, I) * (1 / D)
PRINT USING "###"; INV(I, J);
PRINT " ";
NEXT
NEXT
100 END
SUB INVERSE
END SUB
Friday, 28 September 2012
Augmented quote.
course, if you're a (QBASIC) programmer. ;)
QBASIC program testing tip.
I want to share this simple tip about testing QBASIC codes that
require the user to input several numbers or needs several different
random numbers to run.
Let's say the code is to compute the average of the ages of 200 or
more people, (final purpose), you can reduce the number of iterations
to, say 10 if you'll be entering the values by yourself or you can
leave it at 200 and do this:
where you have the statement
INPUT AGE%(I)
for example, you can replace it with
AGE% (I) = RND * 50
for random integer ages ranging 0 to 50. But if the range is from
something like 20 to 50 you'll code it like this:
AGE%(I) = 20 + (RND * 30) '30 = 50 - 20
To your programming success, Ikformula.
On 4/19/12, bartholomew ikechukwu <ikechukwu4god@gmail.com> wrote:
> Check out this QBASIC program to produce a bar chart from inputted data.
>
> CLS
> SCREEN 12
> ' THIS PROGRAM PLOTS A BAR CHART OF 12 BARS
>
> INPUT " CHOOSE THE COLOR OF YOUR BARS,ANY ONE OF BLUE, GREEN, RED AND
> YELLOW"; COL$
>
> SELECT CASE COL$
> CASE "BLUE"
> LET A = 9
> CASE "GREEN"
> LET A = 10
> CASE "RED"
> LET A = 12
> CASE "YELLOW"
> LET A = 14
> CASE "blue"
> LET A = 9
> CASE "green"
> LET A = 10
> CASE "red"
> LET A = 12
> CASE "yellow"
> LET A = 14
>
> END SELECT
> LINE (10, 200)-(10, 400)
> LINE (10, 400)-(600, 400)
>
> FOR X = 35 TO 600 STEP 50
> INPUT "INPUT VERTICAL VALUE <= 200 "; Y
> LINE (X, (400 - Y))-((X + 30), 400), A, BF
> NEXT X
>
> END
>
Thursday, 19 April 2012
QBASIC program to produce bar charts or Histograms?
CLS
SCREEN 12
' THIS PROGRAM PLOTS A BAR CHART OF 12 BARS
INPUT " CHOOSE THE COLOR OF YOUR BARS,ANY ONE OF BLUE, GREEN, RED AND
YELLOW"; COL$
SELECT CASE COL$
CASE "BLUE"
LET A = 9
CASE "GREEN"
LET A = 10
CASE "RED"
LET A = 12
CASE "YELLOW"
LET A = 14
CASE "blue"
LET A = 9
CASE "green"
LET A = 10
CASE "red"
LET A = 12
CASE "yellow"
LET A = 14
END SELECT
LINE (10, 200)-(10, 400)
LINE (10, 400)-(600, 400)
FOR X = 35 TO 600 STEP 50
INPUT "INPUT VERTICAL VALUE <= 200 "; Y
LINE (X, (400 - Y))-((X + 30), 400), A, BF
NEXT X
END
Monday, 16 April 2012
A simple program to change any number in base ten to another base.
problems, this little code here can help you.
CLS
'THIS PROGRAM CHANGES ANY NUMBER IN BASE TEN TO ANY BASE YOU
'WISH TO CHANGE IT TO
DIM B(30)
INPUT "THE NO IN BASE TEN"; D
INPUT "THE NEW BASE YOU WANT TO CHANGE IT TO"; NB
CLS
BT = D
DO
K = K + 1
I = I + 1
E = D MOD NB
D = D \ NB
B(I) = E
LOOP UNTIL D < NB
PRINT
PRINT
PRINT BT; "IN BASE"; NB; "IS"
B(I + 1) = D
FOR I = K + 1 TO 1 STEP -1
COLOR 6
PRINT USING "#"; B(I);
NEXT I
END
Qbasic program to produce a multiplication table of variable width & height, accompanied with rows and columns.
'IT'S KINDA DYNAMIC, THIS AND MORE CAN BE ACHIEVED WITH QBASIC
DECLARE SUB BRAND ()
CLS
SCREEN 12
'PROGRAM TO PRODUCE MULTIPLICATION TABLE
INPUT "INPUT THE THE DESIRED WIDTH OF THE TABLE"; X
INPUT "INPUT THE THE DESIRED LENGTH OF THE TABLE"; Y
SX = 6
SY = 15
CLS
CALL BRAND
CLS
PRINT
FOR A = 1 TO Y
FOR B = 1 TO X
COLOR 14
PRINT USING "###"; A * B;
PRINT " ";
NEXT
PRINT
NEXT
LINE (SX - 5, SY - 5)-(31.5 * X + 5, (15.89 * Y + 20)), 13, B
LINE (SX, SY)-(31.5 * X, (15.89 * Y) + 15), 15, B
'THIS FIRST LOOP DRAWS THE FIRST TWO VERTICAL LINES
FOR LX = 37.5 TO (31.5 * 3) STEP 31.5
LINE (LX, SY)-(LX, (15.89 * Y) + SY), 9
NEXT
'THIS DRAWS THE REMAINING VETICAL LINES
FOR LX2 = 94.5 TO (31.5 * X) STEP 31.5
LINE (LX2, SY)-(LX2, (15.89 * Y) + SY), 10
NEXT
'THIS LOOP DRAWS ALL THE HORIZONTAL LINES
FOR LY = 30.89 TO (15.89 * Y) STEP 15.89
LINE (SX, LY)-(31.5 * X, LY), 3
NEXT
END
SUB BRAND
PRINT
PRINT
PRINT
PRINT " MULTIPLICATION TABLE PROGRAM"
PRINT " COMPLETED BY"
COLOR 9
PRINT " IKFORMULA "
SLEEP 2
END SUB
Friday, 13 April 2012
Program to create an analog clock.
CLS
SCREEN 12
SECONDHAND = 80
MINHAND = 65
HOURHAND = 50
OX = 200 'THESE IS THE CENTER OF THE CLOCK
OY = 250
RADIUS = 100
DO
FOR H = .10464 TO 6.2784 STEP .5232 'the angles are already in radians
FOR M = .10464 TO 6.2784 STEP .10464
FOR S = .10464 TO 6.2784 STEP .10464
'************************************************************************
FOR H2 = 0 TO 5.7552 STEP .5232 'to create the marks all
S4X = OX + ((SECONDHAND + 10) * COS(H2)) 'around the face of the
S4Y = OY + ((SECONDHAND + 10) * SIN(H2)) 'clock
S5X = OX + ((SECONDHAND + 15) * COS(H2))
S5Y = OY + ((SECONDHAND + 15) * SIN(H2))
LINE (S5X, S5Y)-(S4X, S4Y)
NEXT H2
'***********************************************************************
FOR S2 = .10464 TO 6.2784 STEP .10464
S2X = OX + ((SECONDHAND + 20) * COS(S2))
S2Y = OY + ((SECONDHAND + 20) * SIN(S2))
S3X = OX + ((SECONDHAND + 15) * COS(S2))
S3Y = OY + ((SECONDHAND + 15) * SIN(S2))
LINE (S3X, S3Y)-(S2X, S2Y)
CIRCLE (OX, OY), 95
NEXT S2
SX = OX + (SECONDHAND * COS(S))
SY = OY + (SECONDHAND * SIN(S))
MX = OX + (MINHAND * COS(M))
MY = OY + (MINHAND * SIN(M))
HX = OX + (HOURHAND * COS(H))
HY = OY + (HOURHAND * SIN(H))
LINE (OX, OY)-(SX, SY), 4 'Second hand
LINE (OX, OY)-(MX, MY), 14 'MINUTE hand
CIRCLE (MX, MY), 5
LINE (OX, OY)-(HX, HY) 'HOUR hand
CIRCLE (HX, HY), 5
CIRCLE (OX, OY), RADIUS
CIRCLE (OX, OY), RADIUS + 10
CIRCLE (OX, OY), 5, 1
SLEEP 1
SOUND 4000, .1
CLS
NEXT S
NEXT M
NEXT H
LOOP
END
Friday, 23 March 2012
Sunday, 11 March 2012
The keys to creating graphically oriented programs in QBASIC
QBASIC, I aim to answer this question in detail as much as I can.
1. You need to have a good knowledge of the QBASIC keywords and their
syntax. QBASIC has a very extensive help file, do try to look into it
from time to time to have a very strong knowledge of the keywords.
2. Have a good understanding of loops as they'll be used to manipulate
variables to create the needed effects on the screen. These loops are:
FOR-TO-NEXT, IF-THEN-ELSE, DO-WHILE-LOOP, DO-UNTIL-LOOP, WHILE-WEND.
3. Understand the screen type you're using, I use screen 12 (640x480)
most of the time. Know the particular colors that work in that screen
type.
4. A graph sheet is indispensable, as it gives you an idea of what
your program will look like when it's ran. Try to give it a scale such
that it matches your screen type (remember that the y axis in QBASIC
increases from top down).
5. One thing you really need to know is this, graphics involve
numbers, manipulate this numbers well and you'll do wonders in QBASIC.
Making use of formulae, loops, increments.
I hope that you understand all this and have a great time programming
in QBASIC. Should I have more tips, they'll be posted quickly, you can
use the comments box below.
QBASIC Program To produce prime numbers
OPEN "Prime.txt" FOR OUTPUT AS #1
INPUT "UP TO WHICH NUMBER DO YOU
NEED"; N
DIM a(N)
a(1)=0 For i =2 To N/2 step 1 a(i)=1 For j=2 To N/i step 1
a(i*j)=0
Next j
Next i
For i =1 To N step 1
if a(i)=1 Then Print #1, i;"is prime"
Print '(empty if sent to notepad, Your
result is in the notepad,
check for PRIME.txt)
Next i
END
Thursday, 9 February 2012
QBASIC Program To Solve For The Determinant Of An Order 3 Matrix Using Sarrus Method.
CLS
'PROGRAM TO SOLVE FOR THE DETERMINANT OF AN ORDER 3 MATRIX USING SARRUS METHOD"
'THIS VERSION USES THE READ/DATA STATEMENT
DIM M(3, 3)
'INPUT THE ELEMENTS IN THE ORDER OF TOP TO BOTTOM AND LEFT TO RIGHT
DATA 2,3,2,4,1,3,2,4,3
FOR I = 1 TO 3
FOR J = 1 TO 3
READ M(I, J)
NEXT J
NEXT I
D = M(1, 1) * M(2, 2) * M(3, 3) + M(1, 2) * M(2, 3) * M(3, 1) + M(1,
3) * M(2, 1) * M(3, 2) - M(3, 1) * M(2, 2) * M(1, 3) - M(3, 2) * M(2,
3) * M(1, 1) - M(3, 3) * M(2, 1) * M(1, 2)
PRINT "THE DETERMINANT IS"; D
END
version 1.0.2
CLS
'PROGRAM TO SOLVE FOR THE DETERMINANT OF AN ORDER 3 MATRIX USING SARRUS METHOD"
'THIS VERSION USES THE INPUT STATEMENT
DIM M(3, 3)
FOR I = 1 TO 3
FOR J = 1 TO 3
PRINT I; ","; J
INPUT M(I, J)
NEXT J
NEXT I
D = M(1, 1) * M(2, 2) * M(3, 3) + M(1, 2) * M(2, 3) * M(3, 1) + M(1,
3) * M(2, 1) * M(3, 2) - M(3, 1) * M(2, 2) * M(1, 3) - M(3, 2) * M(2,
3) * M(1, 1) - M(3, 3) * M(2, 1) * M(1, 2)
PRINT "THE DETERMINANT IS"; D
END
nRelate - All Sections
nRelate - All Sections
About Me
|