how to find the given number is prime or not?

Answer Posted / amit kumar

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,flag=0,ctr;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=sqrt(n);ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    2 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the Advantages of using macro

874


What is modeling?

807


can anyone suggest some site name..where i can get some good data structure puzzles???

1832


Difference between MAC vs. IP Addressing

822


Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

759


What are void pointers in c?

748


What does a function declared as pascal do differently?

789


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

2065


Why malloc is faster than calloc?

782


What is enumerated data type in c?

829


What is the significance of an algorithm to C programming?

776


What is %lu in c?

887


What are the benefits of organizational structure?

751


Write the syntax and purpose of a switch statement in C.

830


What is nested structure?

760