·
2 min read
Слушать

C Program to Check Whether a Number is Prime or Not

https://docs.vultr.com/clang/examples/check-whether-a-number-is-prime-or-not



C Program to Check Whether a Number is Prime or Not

A prime number is a number greater than 1 that has only two factors: 1 and itself (e.g., 2, 3, 5, 7, 11).


C Program to Check Prime Number

c

Copy

Edit

#include


int main() {

    int num, i, isPrime = 1; // Assume the number is prime (isPrime = 1)


    // Input from user

    printf("Enter a number: ");

    scanf("%d", &num);


    // Prime numbers must be greater than 1

    if (num <= 1) {

        isPrime = 0;

    } else {

        // Check divisibility from 2 to num/2

        for (i = 2; i <= num / 2; i++) {

            if (num % i == 0) {

                isPrime = 0; // If divisible, it's not prime

                break;

            }

0
Give Award

chetankumar kumar

How to Get the ASCII Value of a Character in C In C programming, each character has a unique ASCII (American Standard Code for Information Inter…

Other author posts

Comments
You need to be signed in to write comments

Reading today

Фауст краткое содержание
Мальчик с трубкой
Ryfma
Ryfma is a social app for writers and readers. Publish books, stories, fanfics, poems and get paid for your work. The friendly and free way for fans to support your work for the price of a coffee
© 2025 Ryfma. All rights reserved 12+