Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 - silnia - sprawdzone
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int silnia(liczba)
- {
- if(liczba==1 || liczba==0)
- return 1;
- return liczba*silnia(liczba-1);
- }
- int main(int argc, char *argv[])
- {
- int liczba,suma;
- printf("Podaj liczbe z ktorej program wyznaczy silnie.\n");
- scanf("%d",&liczba);
- suma=silnia(liczba);
- printf("Silnia z podanej liczby wynosi %d.",suma);
- }
- 2 - wyswietlanie - niesprawdzone
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void wypisz(const char* tekst)
- {
- static int nr=0;
- if(tekst[nr]!='\0')
- {
- printf("%c",tekst[nr]);
- nr++;
- wypisz(tekst);
- }
- nr=0;
- }
- const char* tekst="Ala ma kota";
- int main(int argc, char *argv[])
- {
- wypisz(tekst);
- wypisz(tekst);
- wypisz(tekst);
- }
- 3- fibonacci - nie sprawdzone
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int ciag(int liczba)
- {
- if(liczba==0)
- return 0;
- if(liczba==1)
- return 1;
- return ciag(liczba-2)+ciag(liczba-1);
- }
- int main(int argc, char *argv[])
- {
- int liczba,suma;
- int i;
- for(i=5;i<=25;i++)
- {
- suma=ciag(i);
- printf("Suma %d\n",suma);
- }
- }
- 4. systemy liczbowe - sprawdzone
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void sys(int liczba,int system)
- {
- if(liczba>=system)
- sys(liczba/system,system);
- if(liczba%system>10)
- {
- if(liczba%system==10)
- printf("A");
- if(liczba%system==11)
- printf("B");
- if(liczba%system==12)
- printf("C");
- if(liczba%system==13)
- printf("D");
- if(liczba%system==14)
- printf("E");
- if(liczba%system==15)
- printf("F");
- }
- else
- printf("%d",liczba%system);
- }
- const char* tekst="Ala ma kota";
- int main(int argc, char *argv[])
- {
- printf("System dwojkowy: ");
- sys(100,2);
- printf("\nSystem czworkowy: ");
- sys(100,4);
- printf("\nSystem osemkowy: ");
- sys(100,8);
- printf("\nSystem dziesietny: ");
- sys(100,10);
- printf("\nSystem dwunastkowy: ");
- sys(100,12);
- printf("\nSystem szesnastkowy: ");
- sys(100,16);
- }
- 5. suma tablicy - niesprawdzone
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int tab[]={100,2,5};
- int dl=sizeof(tab)/sizeof(tab[0]);
- int dodawanie(int *tab,int dl)
- {
- if((dl-1)==0)
- return tab[dl-1];
- return tab[dl-1]+dodawanie(tab,dl-1);
- }
- int odejmowanie(int *tab,int dl)
- {
- if(dl==1)
- return *tab;
- return (2*tab[0])-dodawanie(tab,dl);
- }
- int iloczyn(int *tab,int dl)
- {
- if(dl==1)
- return *tab;
- if((dl-1)==0)
- return tab[dl-1];
- return tab[dl-1]*iloczyn(tab,dl-1);
- }
- int iloraz(int *tab,int dl)
- {
- if(dl==1)
- return *tab;
- return (tab[0]*tab[0])/(iloczyn(tab,dl));
- }
- int suma=0;
- int roznica=0;
- int mnozenie=0;
- int dzielenie=0;
- int main(int argc, char *argv[])
- {
- suma=dodawanie(tab,dl);
- printf("Suma: %d",suma);
- roznica=odejmowanie(tab,dl);
- printf("\nRoznica: %d",roznica);
- mnozenie=iloczyn(tab,dl);
- printf("\nMnozenie: %d",mnozenie);
- dzielenie=iloraz(tab,dl);
- printf("\nDzielenie calkowite: %d",dzielenie);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement