Ask Question - Get Answer

1 Ans Write a C program to check a Prime number

Asked by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:39 PM at (Education Tutorials)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

A C program to check prime number :


#include<stdio.h>

int isPrime(int n)

{

    int i;

    if(n<=1) return 0;

    for(i=2; i*i<n; i++)

    {

        if(n%i==0)

            return 0;

    }

    return 1;

}

int main()

{

    int n, result;

    printf("Enter a Number\n");

    scanf("%d", &n);

    result = isPrime(n);

    if(result==1)

        printf("%d is a Prime number", n);

    else

        printf("%d is not a Prime number", n);

    return 0;

}


Answered by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:41 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

1 Ans Write a C program to find nth Fibonacci number

1 Ans Write a C program to Find Armstrong Number series upto a Number

1 Ans Write a C program to print Pascal Triangle

1 Ans Write a C program to print Fibonacci number using recursion

1 Ans Which is the best and easy C programming learning website ?

1 Ans Single Digit Interest Rate in the Banking Sector: Problems and Prospects - essay writing

1 Ans Write a C Program to find factorial using recursion

1 Ans Write a C Program to check Anagrams of two strings

1 Ans Write a C program to check Bubble sort data structure and algorithm

1 Ans How to Learn HTML - HyperText Markup Language easily?