Pages

Determining whether the given number is prime or not in C

This program test the prime number.

#include <stdio.h>
#include <conio.h>
void main()
{
     int num, i, c = 0;
     printf("Enter number: ");
     scanf("%d", &num);
   
    for(i = 1; i <= num; i++)
   {
        if(num % i == 0)
           c++;

    }
 
    if(c == 2)
         printf("Given number %d is Prime.", num);
    else
        printf("Given number %d is not Prime.", num);


   getch();
}

@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment