Advertisement
DeMorgan

Untitled

Dec 3rd, 2013
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. void za4_1 (int * pole, int const k, int const n) {
  6.     int i;
  7.     for (i = 0; i < n; i++)
  8.     {
  9.         *(pole + i) = (i+1)*k%n;
  10.     }
  11. }
  12.  
  13. char za4_2(int x) {
  14.     if(x>=0 && x<=35) {
  15.         if(x>=0 && x<=9) {
  16.             return '0'+x;
  17.         } else {
  18.             x -=10;
  19.             return 'a'+x;
  20.         }
  21.     } else {
  22.         return ' ';
  23.     }
  24.    
  25.    
  26. }
  27.  
  28. char * za4_3(int const pole[], int const n) {
  29.     char * retazec;
  30.     int i,x;
  31.     if(n<1)
  32.         return NULL;
  33.     retazec = (char *) malloc(sizeof(char)*n);
  34.    
  35.     for (i = 0; i < n; i++) {
  36.         x = pole[i];
  37.         if(x>=0 && x<=35) {
  38.             if(x>=0 && x<=9) {
  39.                 *(retazec+i) = '0'+x;
  40.             } else {
  41.                 x -=10;
  42.                 *(retazec+i) = 'a'+x;
  43.             }
  44.         } else {
  45.             *(retazec+i) = ' ';
  46.         }
  47.     }
  48.     return retazec;
  49. }
  50.  
  51. void vypisPole (int const pole[], int const n) {
  52.     int i;
  53.     printf("{ ");
  54.     for (i = 0; i < n; i++)
  55.     {
  56.         if(i>0)
  57.             printf(", ");
  58.         printf("%d",pole[i]);
  59.        
  60.     }
  61.     printf("}\n");
  62. }
  63.  
  64. int za4_4 (char const retazec[]) {
  65.     int i, n, pocet, prevIsNum;
  66.  
  67.     n = strlen(retazec);
  68.     pocet = 0;
  69.     prevIsNum = 0;
  70.  
  71.     for (i = 0; i < n; i++)
  72.     {
  73.         if(retazec[i]>='0' && retazec[i]<='9') {
  74.             if(prevIsNum==0) {
  75.                 prevIsNum = 1;
  76.                 pocet++;
  77.             }
  78.         } else {
  79.             if(prevIsNum==1)
  80.                 prevIsNum = 0;
  81.         }
  82.     }
  83.     return pocet;
  84. }
  85.  
  86.  
  87.  
  88. int main() {
  89.     int pole[5];
  90.     char * retazec = NULL;
  91.    
  92.     za4_1 (pole, 2, 5);
  93.     vypisPole (pole, 5);
  94.    
  95.     printf("%c\n",za4_2(35));
  96.     retazec = za4_3(pole,5);
  97.     printf("%s\n",retazec);
  98.    
  99.    
  100.    
  101.    
  102.     // dealokacia dynamickeho pola z funkcie za4_3
  103.     if(retazec!=NULL)
  104.         free((void*)retazec);
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement