0
Write a program to print an natural number in QBasic statements ? Using FOR LOOP
8 Respostas
+ 2
I have 2 questions
1. Why are you learning BASIC? Last time I checked (around 5 years ago), I couldn't even find an interpreter for it. I don't see any real point in learning BASIC now (Disclaimer: I might be wrong here and I'd love to be corrected)
2. Why would you need a for-loop to print a single number? for-loops are used when you need to operate on a series of numbers
Anyways, this is the only resource I found which covers the whole language. There is a section for for-loops in it, you can check that out
https://upload.wikimedia.org/wikipedia/commons/6/6c/QBasic_v1.2.pdf
+ 2
RKK oh right! Even I had that!
Shankar Verma first of all, read my second point again. I don't see any reason of using a for loop to print a single natural number.
Kindly read your question again. It may be that you were being asked to print the first n natural numbers or something like that. If that is the case, see the link I gave you in my previous answer. for-loops are covered there.
OR it may be that you misread the question and did not need a for-loop, in which case also, the link in my previous answer covers how to print numbers to the screen.
If what you've written in the question title is the correct, then please ask your computer teacher.
+ 2
Sempy done already. See my answer before.
+ 1
Ok
+ 1
Nahi aa Raha hai
0
Shankar Verma normally I would request to see your attempt. However, in consideration that SoloLearn has no BASIC course or examples I will make an exception.
10 dim n as integer
20 dim i as integer
30 print "Enter loop limit: ";
40 input n
50 for i = 1 to n
60 print i
70 next i
80 end
Feel free to make adjustments. For instance, line numbers are not needed in QBASIC. They may be removed. Another option is to combine the print and input statement into only an input statement with a string prompt. The index variable i is optional on the "next i" statement, so it may be simplified to just "next". The "end" statement is optional and may be removed.
I hope you find it useful!
0
Write a program in Q Basic to ask a number and print the first n natural number