• WAP to input any number and check whether the given no. Is divisible by 5 or not.
QBasic - number series, bases & manipulation Numbers My wife likes mathematics. She's got a MS in it, she teaches it at degree level and one of her pastimes is solving mathematical puzzles. This page is dedicated to her. Having said that, any mistakes in the programs on this page are all my fault. ' Well, if I called the wrong number, why did you answer?' James Thurber, New Yorker, June 5th 1937.
PI:- Oddly enough there isn't a built in constant for PI, but it's easily calculated yourself. You can define a number variable as a SINGLE or LONG and use ATN(1) * 4 For example using DIM PI AS SINGLE PI = ATN(1) * 4 will give PI as 3.141593, using DIM PI AS DOUBLE PI = ATN(1) * 4 will give PI as 3.89793 nth Roots:- QBasic hasn't a built in function for finding the nth root of a number, but it isn't too hard to find the nth root of any number yourself.
Dec 19, 2014 WAP to print the sum of square of odd numbers up to 100. WAP using to display first 13 odd numbers. DECLARE SUB SERIES. PROGRAM TO DISPLAY SUM. Home / Programming Language / QBASIC: ODD AND EVEN NUMBER. IS = 0 PRINT 'The number is Even number. A PROGRAM TO CALCULATE THE AVERAGE OF A NUMBER.
This is due to the fact that the nth root of a number is the number raised to the (1/n) power. 'nRoot.bas Ray Thomas April 2002 'The nth root of a number is the number raised to the (1/n) power: DIM Num AS DOUBLE DIM Root AS DOUBLE DIM Count AS INTEGER CLS PRINT INPUT 'Please input the number you want the roots of'; Num PRINT PRINT ' n', ' nth root',, ' nth root ^ n' PRINT FOR Count = 1 TO 10 Root = Num ^ (1 / Count) PRINT Count, Root, Root ^ Count NEXT Count END The program also demonstrates how errors creep into calculations, even when the numbers used are DIM'd as DOUBLES. Number Bases:- This program is able to convert from any number to any other number base. It has a flaw in it. Although the program can convert to any base number, I'm not sure what happens after Base 37, this is because after the decimal system in order to add the extra figures needed to the number series, A = 10, B = 11, C = 12 etc. I've no idea what happens after Z is reached, so I've left the program adding the characters from the ASCII table. Q: Why do mathematicians often confuse Halloween and Christmas?
A: Because Oct 31 = Dec 25 To convert a decimal number to another base it's best to make a list of the powers of that base:. X 10, X 9, X 8, X 7, X 6, X 5, X 4, X 3, X 2, X 1, X 0 Any number to the power of 0 is 1, any number to the power of 1 is that number. For Base 3 the powers are:. 19683, 6561, 2187, 729, 243, 81, 27, 9, 3, 1 Say you want to see what 169 is to base 3, the largest number that can go into 169 is 81 which goes into it twice, remainder 7. 27 and 9 can't go into 7 so these positions become 0's.
The next power that can go into 7 is 3, which goes into it twice, remainder 1. This means that 169 as Base 3 is 20021.
What is happening is that we are doing a long division. To change a number in a Base back to decimal we once again write the powers of that base and write the number beneath it. We then can then count off the number as a decimal. Screenshot of Numbase.bas. DIM UserNum AS DOUBLE UserStr$ = ' Posn = INSTR(UserStr$, '/') Num = VAL(LEFT$(UserStr$, Posn - 1)) Den = VAL(MID$(UserStr$, Posn + 1)) UserNum = Num / Den I've also limited the program to only run the Harmon subroutine when 'C' is chosen and when the number input is less than 4.
Fifa 6 Game. This is again due to the factorisation. If a number great than 4 is input the program takes an age to do the calculations. If this code to do this is removed then there is now reason for the limitation on numbers less than 4. However, the program will take a long, long to reach the number that the user input. Mersenne Prime Numbers:- This is a prime number series of numbers which is given by 2 p - 1, where p is a prime number and so is the Mersenne Prime derived from it.
Whilst writing the program I came across a limit of the MOD command in QBasic. The limit is that it only works for numbers less or equal than 2,147,483,647, which is the limit for a long integer, oddly enough this is also a Mersenne Prime. If you've a couple of hours or days you don't mind leaving your computer running you may like to replace the lines.
NewNum = (MersTest / MersDiv) * 1000 NewStr$ = STR$(NewNum) IF RIGHT$(NewStr$, 3) = '000' THEN MersPrime = 1 You'll also need to define NewNum as a DOUBLE. This has the same result as IF MersTest MOD MersDiv = 0 THEN MersPrime = 1 but can deal with very large numbers. The problem is that the program is VERY slow to run.
For this reason I've limited the program to calculating the first 8 numbers in the series. The series is 3, 7, 31, 127, 8191, 131071, 524287,, 884105727. These are Mersenne Primes from the normal primes of 2, 3, 5, 7, 13, 17, 19, 31 and 61 Pascal Numbers:- This is the series of numbers which are the sums of the numbers in each line of Pascal's Triangle. This is a wonderful of construct of numbers in which can be seen the Magic 11's, the Fibonacci sequence, Catalan numbers, Triangular numbers, Square numbers and the polygonal numbers. Although all these number series can be seen, it is very simple. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 Can you see how it is made? Each number is the sum of the two numbers above and to either side of it, apart from the outside numbers which are always 1.