Skip to main content

Qbasic Programs for Class 9 & 10

1. WAP to input any number and display the factors.
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "FACTORS OF"; N; "=";
FOR I = 1 TO N
IF N MOD I = 0 THEN PRINT I;
NEXT I
END
USING SUB PROCEDURE
DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END
SUB FACT (N)
PRINT "FACTORS OF"; N; "=";
FOR I = 1 TO N
IF N MOD I = 0 THEN PRINT I;
NEXT I
END SUB




2. WAP to input any number and display the prime factors.
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "PRIME FACTORS OF"; N; "=";
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF N MOD I = 0 AND C = 2 THEN PRINT I;
NEXT I
END
USING SUB PROCEDURE
DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END
SUB FACT (N)
PRINT "PRIME FACTORS OF"; N; "=";
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF N MOD I = 0 AND C = 2 THEN PRINT I;
NEXT I
END SUB
3. WAP to input any number and find sum of factors.
CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN S = S + I
NEXT I
PRINT "SUM OF FACTORS="; S
END
USING SUB PROCEDURE
DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END
SUB FACT (N)
S = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN S = S + I
NEXT I
PRINT "SUM OF FACTORS="; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF FACTORS=";  FACT (N)
END
FUNCTION FACT (N)
S = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN S = S + I
NEXT I
FACT = S
END FUNCTION
4. WAP to input any number and display the factorial of a given number.
CLS
INPUT "ENTER ANY NUMBER"; N
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
PRINT "FACTORIAL ="; F
END
USING SUB PROCEDURE
DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END
SUB FACT (N)
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
PRINT "FACTORIAL ="; F
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "FACTORIAL ="; FACT (N)
END
FUNCTION FACT (N)
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
FACT = F
END FUNCTION
5. WAP to input any number and display the prime factorial of a given number.
CLS
INPUT "ENTER ANY NUMBER"; N
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
PRINT "PRIME FACTORIAL ="; F
END
USING SUB PROCEDURE
DECLARE SUB FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL FACT (N)
END
SUB FACT (N)
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
PRINT "PRIME FACTORIAL ="; F
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION FACT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "PRIME FACTORIAL ="; FACT (N)
END
FUNCTION FACT (N)
F = 1
FOR I = 1 TO N
C = 0
FOR J = 1 TO I
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN F = F * I
NEXT I
FACT = F
END FUNCTION

Comments

Post a Comment

Express your opinion

Popular posts from this blog

Are you Hacked ? A Cozy Guide to Online Security - Must Know

Imagine your online life like a cozy house you’ve built on the internet. You store personal items (emails, photos, bank details) inside it, invite friends and family to visit (social media), and even shop for new items right from your living room (e-commerce). The problem? Hackers are lurking around, trying to sneak in when you’re not looking! Just like you’d lock your front door and install a security camera, you can take simple steps to protect your digital home. In this blog, we’ll walk through some friendly, easy-to-understand methods to keep hackers at bay.  Let’s get started! 1. Check If Your Information Is Out There What This Means Have you ever wondered if someone has your password? Or if your email was part of a major data breach? Tools like Have I Been Pwned , Pentester   can instantly check if your email address or password has been leaked during a hack. Why It’s Important If your credentials are floating around the internet, you’ll want to change those passwords im...

Quantum Computing Trends - 2023

 Introduction Quantum computing stands on the brink of a revolution. This emerging technology, harnessing the principles of quantum mechanics, promises to transform computation by performing complex tasks much faster than current classical computers. In 2023, we witness quantum computing evolving from theoretical constructs to practical, scalable technologies with broad applications in various sectors. Background Study The study of quantum computing has been marked by significant milestones. Initially dominated by theoretical studies and small-scale experimental setups, the field has seen rapid advancements in hardware, software, and algorithm development. Major tech companies and research institutions have been key players in driving these innovations, leading to an increasingly diverse and competitive landscape. Current State and Trends in Quantum Computing IBM's Pioneering Efforts: IBM has been instrumental in advancing superconducting qubits technology. After unveiling a 127-qu...

Beyond the Hype: The Struggles of Breaking into Cybersecurity

  Introduction In today's digital age, cybersecurity is important to protecting sensitive information and infrastructure from ever-changing cyber attacks. With high-profile hacks making news and businesses scrambling to strengthen their defenses, one might think that cybersecurity professionals are in high demand. The facts, however, reveal a different narrative. In their pursuit of a career in cybersecurity, aspiring professionals may encounter a range of difficult obstacles. Despite the industry's rapid growth and ongoing concerns about a shortage of skilled workers, getting a cybersecurity job can be incredibly tough. This article delves into the hard realities that lay beneath the excitement, shedding light on job seekers' hardships and the true nature of the cybersecurity job market. Background According to CISCO, cybersecurity involves protecting systems, networks, and programs from digital attacks. IBM defines it as any technology, measure, or practice aimed at preve...