UrbanPro
true
default_background

Take BSc Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Data Structure and Algorithms check whether the given number is prime or not

Sahas Yadandla
20/08/2025 0 0

In this video, we’ll learn how to write a simple program in C++ to check whether a given number is prime or not.
The program takes an input number from the user, applies a loop to test divisibility, and then tells if it’s a prime number or not prime.

📌 What you’ll learn in this video:

  • What a prime number is (a number divisible only by 1 and itself).

  • How to use loops and conditions in C++.

  • Why for (int i = 2; i * i <= num; i++) is used for optimization.

  • Common mistakes to avoid while writing the logic.

🖥️ Program Explanation:

  1. User enters a number.

  2. If the number is ≤ 1, it’s not prime.

  3. Use a loop to check divisibility from 2 up to √n.

  4. If divisible, mark as not prime; otherwise, it’s a prime number.

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Transistors
A transistor can be used as a switch and signal amplifier. It is an electronic device with three contacts: the emitter (E), base (B) and collector (C). A very small current on the transistor's base can...

STUDY TIP
EAT TULSI LEAVES EVERY MORNING AND DRINK WATER AFTER THAT

secret of knowledge
Before you start learning new things u must know what actually u doing while learing, according to energy principle -Energy can neither be created nor destroyed; rather, it transforms from one form to...

how to write the answer
always highlight the key word of writing any answer without fail,also draw simple figure each and every answer related question accordingly.

Engineering Mechanics
Mechanics is a branch of physics concerned with the action of forces on bodies. Engineers of all disciplines use the concepts explored in this unit to design machines, structures, appliances and products...

Looking for BSc Tuition ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for BSc Tuition Classes?

The best tutors for BSc Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BSc Tuition with the Best Tutors

The best Tutors for BSc Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more