Text preview for : question n answer.pdf part of QBasic programming Question n asnwer



Back to : question n answer.pdf | Home

Specific programming in QBASIC · Determining the area of rectangle · Determining the area of triangle · Convert Celsius from Fahrenheit · Find out a year leap-year or not · Determine an integer is even or odd · Find the maximum minimum number between three numbers · Find the grade letter on basis of mark · Determine the total and the average of some numbers · Find the GCD of two numbers · Find the Factorial of an integer · Test whether a number is prime or not · Find sum of the numbers from 1 to 100 · Find sum of the odd numbers from 1 to 100 · Find sum of squared numbers from 1 to 100 · Sort n numbers
------------ --------- --------- --------- --------- -Please type the code as following in QBASIC program for determining the area and perimeter of a rectangle: CLS REM this program will determine the area and perimeter of a rectangle INPUT "Please enter the Length= ", 1 INPUT "Please enter the width= ", w P=2 * (1+w) a=1 *w PRINT PRINT "The area of the rectangle is= "; a PRINT PRINT "The Perimeter of the rectangle is="; p END Please type the code as following in QBASIC program for determining the area and perimeter of a rectangle: CLS REM this program will determine the area and perimeter of a rectangle INPUT "Please enter the Length= ", 1 INPUT "Please enter the width= ", w P=2 * (1+w) a=1 *w PRINT PRINT "The area of the rectangle is= "; a PRINT PRINT "The Perimeter of the rectangle is="; p END

Please type the code as following in QBASIC program for determining the area of a triangle: 1 | Page Sital Prasad Mandal

Specific programming in QBASIC
CLS REM determine the area of a triangle INPUT "Please insert the length of 3 line (A, B, C) of triangle= ", a, b, c S= (a+b+c)/2 Area=SQR(s * (s-a) * (s-b) *(s-c)) PRINT PRINT "The Area of the triangle is= "; area END Please Type the code as following in QBASIC program to convert Celsius from Fahrenheit: CLS REM "converting Celsius from Fahrenheit" INPUT "Fahrenheit= ", f C=f/2.664864864864# PRINT PRINT "Celsius= "; c END Please Type the code as following in QBASIC program to find out a year is leap year or not: CLS INPUT "The year is= " , y IF (y MOD 4=0) THEN PRINT "This is a leap year" ELSE PRINT "This is not a leap year" END IF END 2 | Page Sital Prasad Mandal

Specific programming in QBASIC
Please Type the code as following in QBASIC program to find out a number is even or odd: CLS REM "Determine an integer is even or odd" INPUT "Enter the number here= ", n IF n MOD 2=0 THEN PRINT "This number is Even" ELSE PRINT "This number is Odd" END IF END Please Type the code as following in QBASIC program to find the Maximum and minimum number from three numbers: CLS INPUT "Please input the 1st number= ", a INPUT "Please input the 2nd number= ", b INPUT "Please input the 3rd number= ", c Max=a IF b > max THEN max= b IF c > max THEN max= c PRINT "The largest number is= "; max Min= a IF b < min THEN min = b IF c < min THEN min = c PRINT "The Smallest number is = "; min END Please Type the code as following in QBASIC program to determine the grade point basis on Subject mark: CLS REM "Determining the grade point basis on Subject mark" INPUT "Enter the subject mark = ", n IF n >= 80 AND n <= 100 THEN PRINT PRINT "The grade point = A+" END IF IF n >=70 AND n <=79 THEN PRINT PRINT "The grade point = A" END IF IF n >=60 AND n <=69 THEN PRINT PRINT "The grade point = A-" END IF IF n>=50 AND n <=59 THEN PRINT PRINT "The grade point = B" 3 | Page Sital Prasad Mandal

Specific programming in QBASIC
END IF IF n >=40 AND n <=49 THEN PRINT PRINT "The grade point = C" END IF IF n >=33 AND n<=39 THEN PRINT PRINT "The grade point = D" END IF IF n < 33 THEN PRINT PRINT "The grade point = F" END IF END Please Type the code as following in QBASIC program for determining the total & average for three numbers: CLS REM This program will determine average for 3 numbers INPUT "Please enter 1st number = ", a INPUT "Please enter 2nd number = ", b INPUT "Please enter 3rd number = ", c t = a+b+c s =T / 3 PRINT PRINT "The Total is = "; t PRINT PRINT "The average is = ";s END Please Type the code as following in QBASIC program to find the GCD code of two numbers: CLS INPUT "Enter the Largest Number = ", L PRINT INPUT "Enter the Smallest Number = ", S DO WHILE S <> 0 T = L MOD S L=S S=t LOOP PRINT PRINT "The G.C.D code is = "; L END Please Type the code as following in QBASIC program to find the factorial of an integer: CLS 4 | Page Sital Prasad Mandal

Specific programming in QBASIC
REM "A program to find the Factorial of an integer" INPUT "The Factorial of which number: ", n f=1 For j = 1 To n f=f*j NEXT PRINT PRINT "The Factorial of"; n; "is" = "; f END Please Type the code as following in QBASIC program to find the factorial of an integer: CLS REM "A program to find the Factorial of an integer" INPUT "The Factorial of which number: ", n f=1 For j = 1 To n f=f*j NEXT PRINT PRINT "The Factorial of"; n; "is" = "; f END Please Type the code as following in QBASIC program to test whether a number is prime or not: CLS REM "A program to test whether is prime or not" INPUT "Enter a number to test = ", n FOR i = 2 TO SQR (n) R=n MOD i IF r=0 THEN PRINT n; "Is not a prime number" EXIT FOR END IF 5 | Page Sital Prasad Mandal

Specific programming in QBASIC
NEXT i IF r <> 0 THEN PRINT PRINT n; "is a prime number" END Please Type the code as following is QBASIC program to find the sum of the number from 1 to 100: CLS REM "A program to find the sum of the number from 1 to 100 1+2+3...+100" total = 0 FOR s = 1 to 100 STEP 1 total = total + s NEXT s PRINT PRINT "Total is = "; total END Please Type the code as following is QBASIC program to find the sum of the odd number from 1 to 100: CLS REM "A program to find the sum of the odd number from 1 to 100. 1+2+3...+100" total = 0 FOR s = 1 to 100 STEP 2 total = total + s NEXT s PRINT PRINT "Total is = "; total END Q Please Type the code as following is QBASIC program to find the sum of the squared number from 1 to 100: 6 | Page Sital Prasad Mandal

Specific programming in QBASIC
CLS REM "A program to find the sum of squared number form 1 to 100" INPUT "Enter the value of n = ", n total= 0 FOR s = 1 TO n STEP 1 Total = total + s ^ 2 NEXT s PRINT PRINT "Total is = "; total END Please Type the code as following is QBASIC program for sorting N numbers: REM Program to sort some numbers CLS INPUT "How many number enter you = ", N FOR I = 1 to N INPUT "Enter the number: ", A (I) NEXT I FOR I = 1 to (N 1) FOR J = 1 to (N 1) IF A (J) > A (J + 1) THEN SWAP A (J), A (J + 1) NEXT J NEXT I PRINT "Sorted Data: " FOR I=1 to N PRINT A (I) NEXT I END

7 | Page

Sital Prasad Mandal

Specific programming in QBASIC

Solutions of Important questions for practical exam of Qbasic http://www.studenton.com/solutions-of-importantquestions-for-practical-exam-of-qbasic/
Here's a list of programs which are frequently asked in practical exams in internal exams, sendup and SLC exams to SLC students. These are asked even in written exam as well.We are confident that if you practice all the questions given below, you will surely secure full marks.

1) 2) 3) 4) 5) 6) 7) 8) 9)

Wap to check whether a number is armstrong or not. Wap to display reverse form of a input word. Wap to check whether a number is palindrome of not. Wap to print only the vowels for a given word. Wap to ask 2 numbers and find H.C.F. and L.C.M. of given number. Wap to check whether the first character of the word is capital, small or numerical. Wap to ask n numbers and display them in ascending order. Wap to enter full name and display the initials only. Wap to convert time in seconds into exact hours, minutes and seconds.

10) Wap to convert binary into decimal. 11) Wap to convert decimal no. into binary. 12) Wap to find factorial number. 13) Wap to find ab without using the exponent sign(^) 14) Wap to input name and show in ascending order.

Solutions: 8 | Page Sital Prasad Mandal

Specific programming in QBASIC
1) Wap to check whether a number is armstrong or not.

INPUT "NUMBER";N A=N DO R=N MOD 10 SUM=SUM + r^3 N=N10 LOOP WHILE N>0 IF SUM=A THEN PRINT "ARMSTRONG" ELSE PRINT "NOT ARMSTRONG" END IF END

2) Wap to display reverse form of a input word. INPUT "ENTER WORD";A$ FOR I=LEN(A$) TO 1 STEP -1 B$=MID$(A$,1,I) C$=C$+B$ NEXT I PRINT C$

3. Wap to check whether a number is palindrome of not. INPUT `NUMBER';N 9 | Page Sital Prasad Mandal

Specific programming in QBASIC
A=N DO R= N MOD 10 SUM=SUM*10+R N=N10 LOOP WHILE N<>0 IF A=SUM THEN PRINT "PALINDROME" ELSE PRINT "NOT PALINDROME" END IF END

4. Wap to print only the vowels for a given word. CLS INPUT "ENTER WORD";A$ FOR I= 1 TO LEN(A$) B$=MID$(A#,I,1) C$=UCASE$(B$) IF C$= "A" OR C$= "E" OR C$= "I" OR C$= "O" OR C$= "U" THEN PRINT C$ END IF NEXT I END

10 | P a g e Mandal

Sital Prasad

Specific programming in QBASIC
5. Wap to ask 2 numbers and find H.C.F. and L.C.M. of given number. CLS INPUT A INPUT B IF A>B THEN SWAP A,B FOR I=1 TO A R= A MOD I R1= B MOD I IF R=0 AND R1=0 THEN H=I END IF NEXT I L=(A*B)/H PRINT "H.C.F.";H PRINT "L.C.M";L END

6. Wap to check whether the first character of the word is capital, small or numerical. CLS INPUT "ENTER ANY WORD";N$ A$=LEFT$(N$,1) A=ASC(A$) SELECT CASE A CASE 48 TO 57 PRINT "NUMBER" 11 | P a g e Mandal Sital Prasad

Specific programming in QBASIC
CASE 65 TO 90 PRINT "UPPER CASE" CASE 97 TO 122 PRINT "LOWER CASE" CASE ELSE PRINT "IT IS OUT OF RANGE" END SELECT END

7. Wap to ask n numbers and display them in ascending order. INPUT "ENTER TOTAL NUMBER";N DIM ARR(N) CLS FOR I= 1 TO N INPUT "ENTER NUMBER";ARR(I) NEXT I FOR I= 1 TO N-1 FOR J=I+1 TO N IF ARR(I) > ARR(J) THEN SWAP ARR(I), ARR(J) NEXT J NEXT I FOR I=1 TO N PRINT ARR(I) NEXT I END 12 | P a g e Mandal Sital Prasad

Specific programming in QBASIC

8. Wap to enter full name and display the initials only. CLS INPUT "ENTER FULL NAME";N$ C$=LEFT$(N$,1) FOR I= 1 TO LEN(N$) IF MID$(N$,I,1) = " " THEN C$=C$ + MID$(N$,I+1,1) END IF NEXT I PRINT "THE INTITALS ARE";C$ END

9.Wap to convert time in seconds into exact hours, minutes and seconds CLS INPUT "ENTER THE TIME IN SECONDS";SC H=SC/3600 MS=SC MOD 3600 M=MS/60 S= MS MOD 60 PRINT H;":";M ":";S END

10. Wap to convert binary into decimal. INPUT B 13 | P a g e Mandal Sital Prasad

Specific programming in QBASIC
I=0 DO R= B MOD 10 D= D + R * 2^I I=I+1 B=B10 LOOP WHILE B<>0 PRINT "DECIMAL";D END

11.Wap to convert decimal no. into binary. CLS INPUT D B=2 WHILE D<>0 R= D MOD B D=DB B$=STR$(R) + B$ WEND PRINT B$

12. Wap to find factorial number. CLS INPUT "ENTER NUMBER";N F=1 14 | P a g e Mandal Sital Prasad

Specific programming in QBASIC
WHILE N>=1 F=F*N N=N-1 WEND PRINT "FACTORIAL";F END 13. Wap to find ab without using the exponent sign(^) CLS INPUT A INPUT B C=A FOR I=2 TO B A=A*C NEXT I PRINT A END

14. Wap to input name and show in ascending order. CLS INPUT "HOW MANY NAMES";N DIM ARRAY$(N) FOR I=1 TO N INPUT "ENTER NAME";ARRAY$(I) NEXT I C=N-1 15 | P a g e Mandal Sital Prasad

Specific programming in QBASIC
FLAG=1 DO WHILE FLAG=1 FLAG=0 FOR I=1 TO C IF ARRAY$(I)>ARRAY$(I+1) THEN SWAP ARRAY$(I),ARRAY$(I+1) FLAG=1 END IF NEXT I C=C-1 LOOP PRINT "THE NAMES SORTED ARE:" PRINT FOR I=1 TO N PRINT I; ":"; ARRAY$(I) NEXT I END

16 | P a g e Mandal

Sital Prasad