//THE BEST OPTIMISED ALGORITHM TO FIND WHETHER A //NUMBER IS PRIME( USE IT IN C OR C++ LANGUAGE)
//NOTE: MANUAL WAY TO FIND IT IS DIFFICULT
#include
#include
#include
#include
struct node
{
int num;
node *link;
}*head;
void add(int,node**);
void divisor(int,node**);
void display(node*);
void main()
{
//add(1,&head);
add(2,&head);
add(3,&head);
int flag=1;
int n;
printf("\nEnter a number:");
scanf("%d",&n);
for(int i=5;i<=n;i+=2)
{
divisor(i,&head);
if(i%6==1)
i+=2;
}
clrscr();
display(head);
node* temp=head;
for(;temp->link!=NULL;)
{
if(n%(temp->num)==0)
{
flag=0;
break;
}
else
{
temp=temp->link;
}
}
if(flag==1)
printf("\n\nPrime");
else
printf("\n\nNot prime");
}
void add(int n, node **head)
{
node *temp;
if((*head)==NULL)
{
*head=(node*)malloc(sizeof(node));
(*head)->link=NULL;
(*head)->num=n;
}
else
{
temp=*head;
while(temp->link)
temp=temp->link;
temp->link=(node*)malloc(sizeof(node));
temp->link->link=NULL;
temp->link->num=n;
}
}
void divisor(int n,node** head)
{
node* temp=*head;
while(temp->link)
{
if(n%(temp->num)==0)
return;
temp=temp->link;
}
if(n%(temp->num))
{
temp->link=(node*)malloc(sizeof(node));
temp->link->num=n;
temp->link->link=NULL;
}
}
void display(node *head)
{
printf("The prime numbers <=given number");
while(head!=NULL)
{cout<num<<" "; head=head->link; }
}
2007-02-14 22:00:24
·
answer #1
·
answered by KillingJoke 3
·
0⤊
4⤋
If it has two faces that are congruent polygons, and those faces are also parallel to each other, then the figure is a prism.
All of the faces have to be polygons, but only two have to be congruent and parallel to make the figure a prism. If there are more than two it's still a prism, for example a cube is a prism. A cylinder has two parallel, congruent faces, but it is not a prism since the faces are circles and not polygons.
2007-02-14 22:05:48
·
answer #2
·
answered by Karen C 3
·
0⤊
0⤋
take one face and slice it parallel to that face. If you get exactly the same face at the cross section "ie, same shape of the same size as the the orriginal face, then your figure is a prism.
2007-02-14 22:01:49
·
answer #3
·
answered by wendywei85 3
·
0⤊
0⤋