How Can Write A Program To Find Prime Numbers?

7

7 Answers

Anonymous Profile
Anonymous answered
Write a program to find out prime numbers between 1to500
jeyanthi aruna Profile
jeyanthi aruna answered
#include<iostream.h>
#include<conio.h>
void main()
{
int  n;
clrscr();
cout<<"Enter any one number:";
cin>>n;
prime(n);
getch();
}
int prime(int x)
{
for(I=2;I<x/2;I++)
{
if(x%I==0)
{
cout<<x<<"is not a primenumber";
return x;
}
cout<<x<<"is a primenumber";
return x;
}
}
 
 
 
 
Ellie Hoe Profile
Ellie Hoe answered
Following is the code. Here you just have to enter the number "n" and then the program will find the prime numbers from 1 till n.
Main()
{
int n,I=1,j,c;  // defining all variables
clrscr();  // clear screen

printf("Enter Number ");
scanf("%d",&n); //enter the number

printf("Prime Numbers Are Following from 1 to %d", &n);

//This loop is for checking the number

while( I <= n)
{
  c = 0;
  for(j=1;j<=I;j++)
{
  if(I%j==0)
     c++; // if number is not prime then c = 1.
}
 if(c==0) // if the number is prime then show the number
 printf("%d",I)
 I++;
  }

}
Anonymous Profile
Anonymous answered
//program to generate prime numbers

#include
#include

void main()

{int prime_no,remainder,divider;

for(prime_no=2;prime_no
Anonymous Profile
Anonymous answered
#include
main()
{
  int n,I=1,j,c;
  clrscr();
  printf("Enter the range");
  scanf("%d",&n);
  printf("Prime Numbers are:");
  while(I
Anonymous Profile
Anonymous answered
Prime number of a student in class

Answer Question

Anonymous