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 Volume of given box in java

class volume { public static void main (String args []) { int l=5,b=6,h=10; int volume; volume=l*b*h; System.out.println (" vol...