Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. 1 - silnia - sprawdzone
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. int silnia(liczba)
  8. {
  9. if(liczba==1 || liczba==0)
  10. return 1;
  11. return liczba*silnia(liczba-1);
  12. }
  13.  
  14.  
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18. int liczba,suma;
  19. printf("Podaj liczbe z ktorej program wyznaczy silnie.\n");
  20. scanf("%d",&liczba);
  21. suma=silnia(liczba);
  22. printf("Silnia z podanej liczby wynosi %d.",suma);
  23. }
  24. 2 - wyswietlanie - niesprawdzone
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. void wypisz(const char* tekst)
  30. {
  31. static int nr=0;
  32. if(tekst[nr]!='\0')
  33. {
  34. printf("%c",tekst[nr]);
  35. nr++;
  36. wypisz(tekst);
  37. }
  38. nr=0;
  39. }
  40.  
  41.  
  42. const char* tekst="Ala ma kota";
  43. int main(int argc, char *argv[])
  44. {
  45. wypisz(tekst);
  46. wypisz(tekst);
  47. wypisz(tekst);
  48. }
  49.  
  50.  
  51.  
  52. 3- fibonacci - nie sprawdzone
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55.  
  56. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  57.  
  58. int ciag(int liczba)
  59. {
  60. if(liczba==0)
  61. return 0;
  62. if(liczba==1)
  63. return 1;
  64. return ciag(liczba-2)+ciag(liczba-1);
  65. }
  66.  
  67.  
  68.  
  69. int main(int argc, char *argv[])
  70. {
  71. int liczba,suma;
  72. int i;
  73. for(i=5;i<=25;i++)
  74. {
  75. suma=ciag(i);
  76. printf("Suma %d\n",suma);
  77. }
  78. }
  79. 4. systemy liczbowe - sprawdzone
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include <string.h>
  83.  
  84. void sys(int liczba,int system)
  85. {
  86. if(liczba>=system)
  87. sys(liczba/system,system);
  88. if(liczba%system>10)
  89. {
  90. if(liczba%system==10)
  91. printf("A");
  92. if(liczba%system==11)
  93. printf("B");
  94. if(liczba%system==12)
  95. printf("C");
  96. if(liczba%system==13)
  97. printf("D");
  98. if(liczba%system==14)
  99. printf("E");
  100. if(liczba%system==15)
  101. printf("F");
  102. }
  103. else
  104. printf("%d",liczba%system);
  105. }
  106.  
  107.  
  108.  
  109. const char* tekst="Ala ma kota";
  110. int main(int argc, char *argv[])
  111. {
  112. printf("System dwojkowy: ");
  113. sys(100,2);
  114. printf("\nSystem czworkowy: ");
  115. sys(100,4);
  116. printf("\nSystem osemkowy: ");
  117. sys(100,8);
  118. printf("\nSystem dziesietny: ");
  119. sys(100,10);
  120. printf("\nSystem dwunastkowy: ");
  121. sys(100,12);
  122. printf("\nSystem szesnastkowy: ");
  123. sys(100,16);
  124.  
  125. }
  126.  
  127. 5. suma tablicy - niesprawdzone
  128. #include <stdio.h>
  129. #include <stdlib.h>
  130. #include <string.h>
  131.  
  132. int tab[]={100,2,5};
  133. int dl=sizeof(tab)/sizeof(tab[0]);
  134.  
  135.  
  136. int dodawanie(int *tab,int dl)
  137. {
  138. if((dl-1)==0)
  139. return tab[dl-1];
  140. return tab[dl-1]+dodawanie(tab,dl-1);
  141. }
  142.  
  143. int odejmowanie(int *tab,int dl)
  144. {
  145. if(dl==1)
  146. return *tab;
  147. return (2*tab[0])-dodawanie(tab,dl);
  148. }
  149.  
  150.  
  151.  
  152. int iloczyn(int *tab,int dl)
  153. {
  154. if(dl==1)
  155. return *tab;
  156. if((dl-1)==0)
  157. return tab[dl-1];
  158. return tab[dl-1]*iloczyn(tab,dl-1);
  159. }
  160.  
  161. int iloraz(int *tab,int dl)
  162. {
  163. if(dl==1)
  164. return *tab;
  165. return (tab[0]*tab[0])/(iloczyn(tab,dl));
  166. }
  167.  
  168.  
  169. int suma=0;
  170. int roznica=0;
  171. int mnozenie=0;
  172. int dzielenie=0;
  173.  
  174. int main(int argc, char *argv[])
  175. {
  176. suma=dodawanie(tab,dl);
  177. printf("Suma: %d",suma);
  178. roznica=odejmowanie(tab,dl);
  179. printf("\nRoznica: %d",roznica);
  180. mnozenie=iloczyn(tab,dl);
  181. printf("\nMnozenie: %d",mnozenie);
  182. dzielenie=iloraz(tab,dl);
  183. printf("\nDzielenie calkowite: %d",dzielenie);
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement