write the program for prime numbers?

Answer Posted / karthik

#include<stdio.h>
#include<conio.h>
void main()
{
int n,flag;
clrscr();
printf("\n Enter prime no\n");
scanf("%d",&n);
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
if(flag==0)
printf("\n%d is not prime",n);
else
printf("\n %d is prime",n);
getch();
}

Is This Answer Correct ?    21 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of realloc()?

667


Why can’t we compare structures?

814


What does #pragma once mean?

684


What is table lookup in c?

626


What is a pointer variable in c language?

643






how can f be used for both float and double arguments in printf? Are not they different types?

606


What are pointers? What are different types of pointers?

626


What is difference between static and global variable in c?

537


Can you please compare array with pointer?

615


Can we change the value of constant variable in c?

572


What is #include in c?

598


Explain setjmp()?

655


What is && in c programming?

676


What are Macros? What are its advantages and disadvantages?

646


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

585