Check whether a number is prime or not | C-Program

Prime number or not:

Tips:

1.Take a variable.
2.Use for loop.
3.Use if and else.

  Code:

#include<stdio.h>

void main()

{
    int a,i;

    printf("Enter a number:\n");

    scanf("%d",&a);

    for(i=2;i<=a-1;i++)

        if(a%i==0)

            break;

    if(a==i)

        printf("Prime number!\n");

    else

        printf("Not a Prime number!\n");

}

Output:


Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :