Program zacina się u mnie powyżej wartości 500 Może ktoś ma jakiś pomysł jak to ruszyć?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct list{
int key;
struct list *next;
struct list *prev;
}list;
void push(list **head, list **tail, int el)
{
list *nowy;
nowy= (list *)malloc(sizeof(list));
nowy->key=el;
nowy->next=NULL;
nowy->prev=NULL;
if(*head==NULL){
*head=nowy;
*tail=nowy;
}
else{
nowy->prev=(*tail);
(*tail)->next=nowy;
(*tail)=nowy;
}
}
void pop(list **head, int element)
{
list *tmp=(*head);
if((*head)==NULL){
printf("Brak elementu");
}
else{
while(tmp!=NULL && tmp->key!=element)
tmp=tmp->next;
if(tmp->next!=NULL){
tmp->prev->next=tmp->next;
free(tmp);}
else{ tmp->prev->next=NULL;
free(tmp);}
}
}
void sito()
{
list *head=NULL;
list *tail=NULL;
list *wsk;
list *wsk2;
list *temp;
int i;
double zakres;
printf("Podaj zakres wyszukiwania: ");
scanf("%d", &zakres);
push(&head,&tail,2);
push(&head,&tail,3);
for(i=2;i<zakres;i++)
{
if(((i%2)!=0) && ((i%3)!=0))
push(&head,&tail,i);
}
wsk2=head->next->next;
wsk=wsk2->next;
while(wsk2->key<floor(sqrt(zakres))){
while(wsk)
{
if(((wsk->key)%(wsk2->key))==0)
{
temp=wsk->next;
pop(&head,wsk->key);
wsk=temp;
}
else wsk=wsk->next;
}
wsk2=wsk2->next;
wsk=wsk2->next;
}
printf("\n\n");
if(head==NULL)printf("Brak elementow do zapisu");
else{
FILE *fp=fopen("D:\\sito.txt", "w");
while(head!=NULL){
fprintf(fp, "%d ", head->key);
head=head->next;
}
fclose (fp);
}
printf("Zapisano liczby do pliku sito.txt z podanego przez Ciebie zakresu\n");
}
int main()
{
sito();
system("pause");
return 0;
}
poprawiłem tag <code>
- msm