Write a program to find out prime numbers between 1to500
#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;
}
}
#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;
}
}
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++;
}
}
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++;
}
}
//program to generate prime numbers
#include
#include
void main()
{int prime_no,remainder,divider;
for(prime_no=2;prime_no
#include
#include
void main()
{int prime_no,remainder,divider;
for(prime_no=2;prime_no
#include
main()
{
int a,c=0,I,n;
printf("enter a no:");
scanf("%d",&a);
for(I=1;I
main()
{
int a,c=0,I,n;
printf("enter a no:");
scanf("%d",&a);
for(I=1;I
#include
main()
{
int n,I=1,j,c;
clrscr();
printf("Enter the range");
scanf("%d",&n);
printf("Prime Numbers are:");
while(I
main()
{
int n,I=1,j,c;
clrscr();
printf("Enter the range");
scanf("%d",&n);
printf("Prime Numbers are:");
while(I
Prime number of a student in class