Computer Science, asked by suvashreebanerjee, 5 months ago

Anyone can answer this question please.
this is my computer assignment.
please help me please.
I am requesting you all. please ​

Attachments:

Answers

Answered by anindyaadhikari13
1

Solution:

1. Write a program in QBASIC to print the first N natural numbers using FOR-NEXT loop.

CLS

INPUT "Enter the value of n: "; N

FOR I = 1 TO N

   PRINT I;

NEXT I

END

Explanation: We ask the user to enter the number. Then a for loop is created which runs for i = 1 to n with default step value of 1. After each iteration, the value of variable 'i' is displayed on screen. In this way, our problem is solved.!!

2. Write a program in QBASIC to print the sum of first N natural numbers using FOR-NEXT loop.

CLS

INPUT "Enter the value of n: "; N

SUM = 0

FOR I = 1 TO N

   SUM = SUM + I

NEXT I

PRINT "Sum of numbers ="; SUM

END

Explanation: We ask the user to enter the number. Then we initialise sum = 0. Then a for loop is created which runs for i = 1 to n with default step value of 1. After each iteration, the value of variable 'i' is added to the sum. When the loop ends, the sum of numbers is displayed on screen. In this way, our problem is solved.!!

Refer to the attachments for output.

Attachments:
Similar questions