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

Explain what is the benefit of using const for declaring constants?

618


What is a floating point in c?

607


Can static variables be declared in a header file?

620


What’s the special use of UNIONS?

663


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1078






What is a char c?

595


C language questions for civil engineering

1248


What is a void pointer in c?

611


What is 2c dna?

611


Can include files be nested? How many levels deep can include files be nested?

660


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

650


When is the “void” keyword used in a function?

845


There seem to be a few missing operators ..

621


Explain void pointer?

594


difference between native and cross compilers

1673