Qbasic program to display all prime numbers from 1 to 100  

Posted by Mahibabu

REM Program to print all prime numbers from 1 to 100
CLS
FOR n = 2 TO 100
FOR k = 2 TO n / 2
flag = 0
r = n MOD k
IF r = 0 THEN
flag = 1
EXIT FOR
END IF
NEXT k
IF flag = 0 THEN PRINT n,
NEXT n
END

7 comments

Worked Well ☺

Assuming a series s=1+1/2+1/3+1/4+1/n
How can one write a program to find n and s in the series.

You could add “STEP 2” to the outer for loop as prime numbers are never even numbers. An as long as you mark the r variable as a single or double precision floating point variable you could add the line “DEFINT a-z” to your code.

Thanks, but I am still confused. I'll love it if you exemplify it, possibly with the series in my question.

I cannot understand!!

Can you print number between 10to100

Nice

Post a Comment

Contributors

My photo
I am Mahesh Bhandari from Kathmandu, Nepal

Check Nepal's Time