100% SET4- 11a: Prog to find prime or not using functions

#include <stdio.h>
void primeornot(int num)
 {
  int i = 2;
  while(i <= num / 2)
  {
    if(num % i == 0)
{
 printf ("\n given number %d is not prime", num);
      break;
}
i++;
  }
  if(i == (num / 2) + 1)
  printf ("\n given number %d is prime", num);
}

void main()
{
  int numb;
  printf ("\nenter a int >1 and <32768 that has to be checked for prime or not:");
  scanf ("%d", &numb);
  if(numb>1 && numb <32768)
   primeornot (numb);
  else
    printf("\n entered number is out of prescribed limits:");
} //end of main 

తెరమీద 

enter a int >1 and <32768 that has to be checked for prime or not:24

 given number 24 is not prime

తెరమీద  మరోసారి 

enter a int >1 and <32768 that has to be checked for prime or not:2

 given number 2 is prime

ఇంకోసారి 
enter a int >1 and <32768 that has to be checked for prime or not:43221

 entered number is out of prescribed limits:

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)