Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //1.usuwa srodek listy jesli nie parzysta
- //2. liczy srednia elementow dodatnich listy
- //3. funkcja przyjmujaca 2 listy, wyswietlajaca ich sume??
- //4. rekurencyjnie z 10 na 6 i na 7
- //5. najwuieksza wartosc niepierwsza z przedzialu, reku.
- typedef struct Node* lista;
- struct Node {
- int wartosc;
- lista *next;
- };
- void pokazListe(lista start){
- lista wypisz = start;
- do{
- printf("Wezel nr: %d\n", wypisz->wartosc);
- wypisz=wypisz->next;
- }
- while(wypisz!=NULL);
- }
- int policz(lista start){
- lista temp=start;
- int zlicz=0;
- while(temp!=NULL)
- {
- temp=temp->next;
- zlicz++;
- }
- return zlicz;
- }
- void deleteMid(lista start){
- lista temp=start;
- lista przechowaj;
- if((policz(temp)%2)==0)
- {
- printf("Lista jest parzysta");
- }
- else
- {
- for(int i=0;i<policz(temp)/2;i++)
- {
- przechowaj=temp;
- temp = temp->next;
- }
- przechowaj->next = temp->next;
- free(temp);
- temp=NULL;
- }
- }
- void srednia(lista start){
- lista temp=start;
- int suma=0,zlicz=0;
- while(temp!=NULL){
- if(temp->wartosc>0)
- {
- suma+=temp->wartosc;
- zlicz++;
- }
- temp=temp->next;
- }
- float srednia=(float)suma/(float)zlicz;
- printf("\nSrednia listy: %f", srednia);
- }
- /*
- ŹLE NAPISANE NIE DZIALA
- lista suma(lista pierwsza, lista druga)
- {
- lista temp1=pierwsza;
- lista temp2=druga;
- for(int i=0;i<policz(temp1);i++)
- {
- for(int j=0;j<policz(temp2);j++)
- {
- if(temp1->wartosc==temp2->wartosc)
- {
- }
- }
- }
- }
- */
- //konwersja na system 7 i 6 z 10
- int naSiedem(int liczba)
- {
- if(liczba==0) return 0;
- naSiedem(liczba/7);
- return printf("%d",liczba%7);
- }
- int naSzesc(int liczba)
- {
- if(liczba==0)return 0;
- naSzesc(liczba/6);
- return printf("%d",liczba%6);
- }
- int czy_pierwsza(int a){
- if(a<2)return 0;
- for(int i=2;i*i<a;i++)
- {
- if(a%i==0)return 0;
- }
- return 1;
- }
- //Nierekurencyjnuie
- int przedzial(int a,int b)
- {
- int max=0;
- for(;a<=b;a++)
- {
- if(czy_pierwsza(a)==0)
- {
- if(max<a) max=a;
- }
- }
- return max;
- }
- //Rekurencyjnie
- int przedzialReku(int a, int b)
- {
- if(a>b)return -1;
- else {
- if(czy_pierwsza(b)==0)return b;
- else return przedzialReku(a,b-1);
- }
- }
- int main()
- {
- printf("Na sys 7:");
- naSiedem(55);
- printf("\nNa sys 7:");
- naSzesc(55);
- printf("\nCzy pierwsza?:");
- if(czy_pierwsza(17)==1)
- {
- printf("Pierwsza");
- }
- else {
- printf("Nie Pierwsza");
- }
- printf("\nNajwieksza niepierwsza z przedzialu?:%d",przedzialReku(5,11));
- lista n1 = (lista)malloc(sizeof(struct Node));
- lista n2 = (lista)malloc(sizeof(struct Node));
- lista n3 = (lista)malloc(sizeof(struct Node));
- lista n4 = (lista)malloc(sizeof(struct Node));
- lista n5 = (lista)malloc(sizeof(struct Node));
- n1->wartosc=1;
- n1->next=n2;
- n2->wartosc=2;
- n2->next=n3;
- n3->wartosc=-3;
- n3->next=n4;
- n4->wartosc=-4;
- n4->next=n5;
- n5->wartosc=5;
- n5->next=NULL;
- lista a1 = (lista)malloc(sizeof(struct Node));
- lista a2 = (lista)malloc(sizeof(struct Node));
- lista a3 = (lista)malloc(sizeof(struct Node));
- lista a4 = (lista)malloc(sizeof(struct Node));
- a1->wartosc=1;
- a1->next=a2;
- a2->wartosc=2;
- a2->next=a3;
- a3->wartosc=3;
- a3->next=a4;
- a4->wartosc=4;
- a4->next=NULL;
- //Wypisywanie;
- printf("\nLista 1:\n");
- pokazListe(n1);
- printf("\nLista 2:\n");
- pokazListe(a1);
- printf("\nPO :\n");
- srednia(n1);
- deleteMid(n1);
- printf("\nLista po usunieciu el srodkowego:\n");
- pokazListe(n1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement