Advertisement
dzieciol

funkcje zad 2

Jan 13th, 2016
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int wczytaj (){
  4.     int x;
  5. printf("podaj liczbe");
  6. scanf("%d",&x);
  7. return x;
  8. }
  9. int najwieksza (int x,int y,int z){
  10.     int maxi;
  11.     maxi=x;
  12.     if (y>maxi)maxi=y;
  13.     if (z>maxi)maxi=z;
  14.     return maxi;
  15. }
  16. int main()
  17. {
  18.     int a,b,c,d,e,f;
  19.     a=wczytaj();
  20.     b=wczytaj();
  21.     c=wczytaj();
  22.     d=wczytaj();
  23.     e=wczytaj();
  24.     f=wczytaj();
  25.     printf("najwieksza z pierwsszych trzech to %d \n",najwieksza(a,b,c));
  26.     printf("najwieksza z kolejnych trzech to %d \n",najwieksza(d,e,f));
  27.     return b;
  28. }
  29.  
  30.  
  31.  ////////zadanie 2//////////
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34.  
  35. int *tw_tab (int r){
  36.     int i;
  37.     int *wsk;
  38.     wsk=malloc(r*sizeof(int));
  39.     for (i=0;i<r;i++){
  40.         printf("t[%d]=",i+1);
  41.         scanf("%d",&wsk[i]);
  42.  
  43.     }
  44. return wsk;
  45. }
  46. int czy_istnieje (int x, int *t, int r) {
  47.     int ind;
  48.     ind = -1;
  49.     int i;
  50.     for (i=0;i<r;i++){
  51.         if(t[i]==x){
  52.             ind = i;
  53.             break;
  54.         };
  55.  
  56.     };
  57.     return ind;
  58. }
  59.  
  60.  
  61. int main()
  62. {
  63.     int *t1;
  64.     int r1,x1,ind1;
  65.     printf ("podaj rozmiar tablicy");
  66.     scanf("%d",&r1);
  67.     printf ("podaj szukaną waqrtosc");
  68.     scanf("%d",&x1);
  69.     t1 = tw_tab(r1);
  70.     ind1 = czy_istnieje(x1,t1,r1) ;
  71.  
  72.     return ind1+1;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement