×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C
Posted by: Damian Pytkowski
Added: May 2, 2016 8:31 PM
Views: 1959
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define LICZBA 5
  5. void los(int t[LICZBA]);//1,2,4,5
  6. int dl_l(int a);//2
  7. void wysw_parz(int t[LICZBA]);//2
  8. void kopia(char *q, char *w);//3
  9. void pok(int t[LICZBA]);
  10. int najmn(int t[LICZBA]);//4
  11. int znajdz(int t[LICZBA],int szuk);//6
  12. void odwroc(int t[]);//5
  13.  
  14. void main()
  15. {
  16.     int tab[LICZBA];
  17.     los(tab);pok(tab);
  18.     printf("\n");
  19.     znajdz(tab,5);
  20. }
  21. int znajdz(int t[LICZBA],int szuk)
  22. {
  23.     int i,q,f=0;
  24.     for(i=0;i<LICZBA;i++)
  25.     {
  26.         if(*(t+i)==szuk){
  27.                 q=i;
  28.                 f=1;}
  29.     }
  30.     if(f==0)return printf("Nie znaleziono.");
  31.     else return q;
  32. }
  33. void odwroc(int t[])
  34. {
  35.     int dl=(LICZBA/2),i;
  36.     int pom1,pom2;
  37.     for(i=0;i<dl;i++)
  38.     {
  39.         pom1=*(t+i);
  40.         pom2=*(t+LICZBA-1-i);
  41.         *(t+i)=pom2;
  42.         *(t+LICZBA-1-i)=pom1;
  43.     }
  44. }
  45. void los(int t[LICZBA])
  46. {
  47.     int i,j;
  48.     srand(time(NULL));
  49.     for(i=0;i<LICZBA;i++)
  50.     {
  51.         for(j=0;j<LICZBA;j++)
  52.             *(t+i)=rand()%100;
  53.     }
  54. }
  55. void wysw_parz(int t[LICZBA])
  56. {
  57.     int i=0,j,m,n=1;
  58.     for(i=0;i<LICZBA;i++)
  59.     {
  60.         j=0;
  61.         for(m=0;m<dl_l(*(t+i));m++)
  62.         {
  63.             j=(*(t+i)-j)/pow(10.0,m);
  64.             if(j%2!=0){n=0;break;}
  65.             j=*(t+i)%10;
  66.         }
  67.         if(n==1)
  68.         printf("%d ",*(t+i));
  69.         n=1;
  70.     }
  71. }
  72. int dl_l(int a)
  73. {
  74.     int i=1;
  75.     while(a>10)
  76.     {
  77.         a=a/10.0;
  78.         i++;
  79.     }return i;
  80. }
  81. void kopia(char *q, char *w)
  82. {
  83.     while(*q)
  84.     {
  85.         *w=*q;
  86.         q++;w++;
  87.     }
  88. }
  89. int najmn(int t[LICZBA])
  90. {
  91.     int i,n=*t;
  92.     for(i=0;i<LICZBA;i++)
  93.         if(*(t+i)<n)
  94.             n=*(t+i);
  95.     return n;
  96. }
  97. void pok(int t[LICZBA])
  98. {
  99.     int i;
  100.     for(i=0;i<LICZBA;i++)
  101.         printf("%d ",*(t+i));
  102. }
  103.  
  104.