write the program for prime numbers?

Answer Posted / pawan kumar

#include<stdio.h>

int main(){

int num,i,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is best book for data structures in c?

599


What is the use of void pointer and null pointer in c language?

626


Explain how do you print an address?

659


Write a program to know whether the input number is an armstrong number.

673


State two uses of pointers in C?

640






What is the 'named constructor idiom'?

640


Why is c called a structured programming language?

677


How many types of functions are there in c?

583


What is a built-in function in C?

796


Here is a neat trick for checking whether two strings are equal

566


What is the purpose of ftell?

601


What does typedef struct mean?

661


What is f'n in math?

621


What are the different types of errors?

646


What is pointer to pointer in c with example?

549