**Article by:** Manish Methani

**Last Updated:** September 27, 2021 at 8:04am IST

A ** prime number** is a number greater than 1 with only two factors – themselves and 1.

A prime number cannot be divided by any other numbers without leaving a remainder.

An example of a prime number is 13. It can only be divided by 1 and 13. Dividing a prime number by another number results in numbers left over e.g. 13 *÷* 6 = 2 remainder 1.

15 is not an example of a prime number because it can be divided by 5 and 3 as well as by itself and 1.

#include int main() { int number = 7; char flag = 0; for(int i = 2; i <= (number/2); i++) { if(number % i == 0) { flag = 1; break; } } if (number == 1) { printf("1 is neither prime nor composite."); } else { if(flag == 0) printf(" %d is a prime number.", number); else printf(" %d is not a prime number.", number); } return 0; }

7 is a prime number.

In this program, a loop is iterated from 2 to number/2. In each iteration, using the condition (number % i) it is checked whether a given number is perfectly divisible by i.

If a number is perfectly divisible by i, then the flag is set to 1 and break. After iteration, we will check whether a given number is 1 or not. if it is 1, the number is considered as a non-prime number else, if the flag is 0, then the given number is a prime number else the number is not a prime number.

10 OS Interview Questions you must know in 2024

10 Angular Interview Questions you must know in 2024

10 Javascript Interview Questions you must know in 2024

Top 10 DSA Interview Questions You should not miss

Top 10 Web Development Interview Questions

Introduction to Next.js

Altina Schinasi: Celebrating the Visionary Designer of Cat-Eye Frames | Google Doodle Tribute

Best Niche for Blogging in USA: A Comprehensive Guide

18 Must-Do Activities for Computer Science Students in College

13 Essential Things Solopreneurs need to know in 2024

25 Practical ways to earn money online

The Power of Gratitude - A Journey to Personal Growth

Top 5 Technology Trends That Are Shaping Our Future

5 Books You Need to Read Right Now

How to answer tell me about yourself?

What Angular feature transforms data before displaying it in the view?

Which widget is used in Flutter to create a button?

6 Mobile App Ideas That You Can Start in 2024

Flutter Widget Showdown: Exploring the Developers Favorite for Layouts!

Mobile App

For Engineers.

Mock Tests.

Test your C Programming skills with this comprehensive mock test on C Programming.

Take TestSolve most asked Interview Questions on Flutter and Test your foundational skills in flutter.

Take TestSolve most asked GATE Questions in Operating Systems and test your Gate Score.

Take TestThis is a mock test designed to help you assess your knowledge and skills in HTML and CSS.

Take TestSolve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.

Take Test