prime number using square root -asr

prime number c program using square root function -asr

#include <stdio.h>
#include <conio.h>
#include <math.h>

void main(){
     int i,n,r,a=0;
clrscr();
printf("Enter number\n");
scanf("%d",&n);


if(n%2==0||n%3==0||n%5==0||n%7==0)
    {
  r=1;
  goto check;
    }

for(i=11,a=1;i<=(int)sqrt(n);i=i+2,a++)
         {

             if(n%i==0)
                                {
                                  r=1;
                                break;
                                }
           }

check:
printf("Loop runned %d times\n",a);

if(r==1)
printf("number is not prime");
else
printf("number is prime");


getch();
}



Comments

Popular posts from this blog

aaabb to32 ,aabbb to a2b3 convert in c-asr

a2b3 output aabbb c program and beautiful use of getchar() ,isdigit() ,atoi() functions and stdlib.h header file-asr

C program to print square spiral number pattern - asr