Prime number or not in C || for loop || C programming

This is a for loop program in which we will check whether the number is Prime or Non-Prime with the help of the C Programming language.




#include <stdio.h>

int main()
{
    int i, m = 0, n, c = 0;
    printf("Enter the Number to check Prime:-\n");
    scanf("%d", &n);
    m = n / 2;

    for (i = 2; i <= m; i++)
    {
        if (n % i == 0)
        {
            printf("%d is not a Prime Number.\n", n);
            c = 1;
            break;
        }
    }
    if (c == 0)
    {
        printf("%d is a Prime Number.\n", n);
    }

    return 0;
}

//......Coded by YASH ALAPURIA



#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post