Q:

C Program To Find Prime Number Using Function

belongs to collection: Function Programs in C

0

C Program To Find Prime Number Using Function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Prime Number Using Function

Algorithm

  • Program Start
  • Declare Variables
  • Input A Number to check prime or not
  • Calling Function
  • Declare some variable
  • Loop Start
  • Check conditions
  • Disoplay result according to condition
  • Function End
  • Program End

Program

//C  Program to check prime number Using Function

#include <stdio.h>
void checkPrime(int n)
{
    int i, count = 0;
    for(i=2; i<n; ++i)
    {
        // check for non prime number
        if(n%i==0)
        {
            count=1;
            break;
        }
    }
    if (count==0)
        printf("%d is a prime number.",n);
    else
        printf("%d is not a prime number.",n);
}
int main()
{
   int n;

    printf("Enter a number to check prime number or not : ");
    scanf("%d",&n);

    checkPrime(n);
}

Output

Enter a number to check prime number or not : 10
10 is not a prime number.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to Find Largest of Three Numbers Using F... >>
<< Factorial of a Number In C Using Function...