Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. 1
  2. #include <stdio.h>
  3. int f(int* a, int b){
  4. int c;
  5. c=*a+5;
  6. *a=*a+5;
  7. b=b+5;
  8. return c;
  9. }
  10.  
  11. int main() {
  12. int a=1, b=1,c;
  13. printf("\nPrije funkcije f:a=%d, b=%d",a,b);
  14. c=f(&a,b);
  15. printf("\nPoslije funkcije f: a=%d, b=%d c=%d",a,b,c);
  16. return 0;
  17. }
  18.  
  19. 2
  20. #include <stdio.h>
  21. int f(int* a, int b){
  22. int c;
  23. c=*a+5;
  24. *a=*a+5;
  25. b=b+5;
  26. return c;
  27. }
  28.  
  29. int main() {
  30. int a=1, b=1,c;
  31. printf("\nPrije funkcije f:a=%d, b=%d",a,b);
  32. c=f(&a,b);
  33. printf("\nPoslije funkcije f: a=%d, b=%d c=%d",a,b,c);
  34. return 0;
  35. }
  36.  
  37. 3
  38. #include <stdio.h>
  39. float maxtemp (float niz[], int br)
  40. {
  41. int i;
  42. float max=niz[0];
  43. for(i=0;i<br;i++)
  44. {
  45. if(niz[i]>max)
  46. max=niz[i];
  47. }
  48. return max;
  49. }
  50. float prtemp(float niz[],int br)
  51. {
  52. int i;
  53. float pr,suma=0;
  54. for(i=0;i<br;i++)
  55. {
  56. suma+=niz[i];
  57. }
  58. return pr=suma/br;
  59.  
  60. }
  61.  
  62. int main() {
  63. int i,n;
  64. float temp[1000];
  65. printf("Unesite broj mjerenja: ");
  66. scanf("%d",&n);
  67. printf("Unesite temperature: ");
  68. for(i=0;i<n;i++)
  69. scanf("%f",&temp[i]);
  70. printf("Maksimalna temperatura: %.1f",maxtemp(temp,n));
  71. printf("\nProsjecna temperatura: %.1f",prtemp(temp,n));
  72. return 0;
  73. }
  74.  
  75. 4
  76. #include <stdio.h>
  77. int drugi(int niz[], int br)
  78. {
  79. int max=0,broj=-1,i,j;
  80. for(i=0;i<br;i++)
  81. {
  82. if(niz[i]>niz[max])
  83. max=i;
  84. }
  85. for(i=0;i<br;i++)
  86. {
  87. if(niz[i]!=niz[max])
  88. {
  89. broj=i;
  90. break;
  91. }
  92. }
  93.  
  94. for(i=0;i<br;i++)
  95. {
  96. if(niz[i]<niz[max] && niz[i]>niz[broj])
  97. broj=i;
  98. }
  99.  
  100. if(max==broj)
  101. return -1;
  102.  
  103. return broj;
  104. }
  105. int main() {
  106. int niz[100],i,vel=0;
  107.  
  108. printf("Unesite niz brojeva: ");
  109. for(i=0;i<100;i++)
  110. {
  111. scanf("%d",&niz[i]);
  112. vel++;
  113. if(niz[i]==-1)
  114. break;
  115. }
  116. printf("Indeks drugog po velicini je: %d",drugi(niz,vel));
  117. return 0;
  118. }
  119.  
  120. 5
  121. #include <stdio.h>
  122. #include <math.h>
  123.  
  124. void zaokruzi(double *niz,int vel)
  125. {
  126. int i;
  127.  
  128. for(i=0;i<vel;i++)
  129. {
  130. if(*(niz+i)>=0)
  131. *(niz+i)=(int)(*(niz+i)*10+0.5)/10.;
  132. else
  133. {
  134. *(niz+i)=fabs(*(niz+i));
  135. *(niz+i)=(int)(*(niz+i)*10+0.5)/10.;
  136. *(niz+i)=-(*(niz+i));
  137. }
  138. }
  139. }
  140. int main() {
  141. printf("Tutorijal 8, Zadatak 5");
  142. return 0;
  143. }
  144.  
  145. 6
  146. #include <stdio.h>
  147. void sortiraj(double *niz, int vel)
  148. {
  149. int i,j,min;
  150. double temp;
  151. for(i=0;i<vel;i++)
  152. {
  153. min=i;
  154.  
  155. for(j=i+1;j<vel;j++)
  156. {
  157.  
  158. if(*(niz+j)<*(niz+min))
  159.  
  160. min=j;
  161. }
  162. temp=*(niz+i);
  163. *(niz+i)=*(niz+min);
  164. *(niz+min)=temp;
  165.  
  166.  
  167.  
  168. }
  169.  
  170.  
  171. }
  172. int main() {
  173. int vel = 10;
  174. double niz[] = {1.2, 8.3, 4.111, -3, 1.19, -1.19, 3.1, 98.7, 0.1, 5.3};
  175. sortiraj(niz, vel);
  176. int i;
  177. for(i = 0; i < vel; i++) {
  178. printf("%g ", niz[i]);
  179. }
  180. return 0;
  181. }
  182.  
  183. 7
  184. #include <stdio.h>
  185. void zamijeni(int *a, int *b)
  186. {
  187. int temp;
  188. temp=*a;
  189. *a=*b;
  190. *b=temp;
  191.  
  192. }
  193. int main() {
  194. int a = 1;
  195. int b = 3;
  196. zamijeni(&a, &b);
  197. printf("%d %d", a, b);
  198. return 0;
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement