Monday, 4 June 2018

How to write program to determine whether a number is prime or not in c

/* program to check prime or not */
# include <stdio.h>
void main ()
int num, counter ;
printf ("\n Enter a number:") ;
scanf ("%d", &num)
counter = 2 ;
while (counter <= num-1)
{
if (num % counter == 0)
{
printf ("\n Not a prime number:") ;
break ;
}
counter++ ;
}
if (counter == num)
printf ("\n prime number:") ;
getch () ;
}

No comments:

Post a Comment

Featured post

Program to find maximum of three number using user define function in C++

A function can be define by the user as per the requirement of the user or programmer . To implement a user define function , a programmer ...