how to find the given number is prime or not?

Answer Posted / rahul tiwari

main()
{
int n,ctr=2,flag=0;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=n/2;ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
flag=9
getch();
}

Is This Answer Correct ?    8 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are c identifiers?

836


Write a program to check whether a number is prime or not using c?

790


what are bit fields in c?

1158


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3956


What are structure types in C?

852


How to explain the final year project as a fresher please answer with sample project

709


pierrot's divisor program using c or c++ code

1952


What is dangling pointer in c?

805


Write a program to reverse a string.

825


How do shell structures work?

782


Write the control statements in C language

853


Why c is called object oriented language?

798


How can I discover how many arguments a function was actually called with?

824


What is structure and union in c?

801


Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.

2910