Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- void za4_1 (int * pole, int const k, int const n) {
- int i;
- for (i = 0; i < n; i++)
- {
- *(pole + i) = (i+1)*k%n;
- }
- }
- char za4_2(int x) {
- if(x>=0 && x<=35) {
- if(x>=0 && x<=9) {
- return '0'+x;
- } else {
- x -=10;
- return 'a'+x;
- }
- } else {
- return ' ';
- }
- }
- char * za4_3(int const pole[], int const n) {
- char * retazec;
- int i,x;
- if(n<1)
- return NULL;
- retazec = (char *) malloc(sizeof(char)*n);
- for (i = 0; i < n; i++) {
- x = pole[i];
- if(x>=0 && x<=35) {
- if(x>=0 && x<=9) {
- *(retazec+i) = '0'+x;
- } else {
- x -=10;
- *(retazec+i) = 'a'+x;
- }
- } else {
- *(retazec+i) = ' ';
- }
- }
- return retazec;
- }
- void vypisPole (int const pole[], int const n) {
- int i;
- printf("{ ");
- for (i = 0; i < n; i++)
- {
- if(i>0)
- printf(", ");
- printf("%d",pole[i]);
- }
- printf("}\n");
- }
- int za4_4 (char const retazec[]) {
- int i, n, pocet, prevIsNum;
- n = strlen(retazec);
- pocet = 0;
- prevIsNum = 0;
- for (i = 0; i < n; i++)
- {
- if(retazec[i]>='0' && retazec[i]<='9') {
- if(prevIsNum==0) {
- prevIsNum = 1;
- pocet++;
- }
- } else {
- if(prevIsNum==1)
- prevIsNum = 0;
- }
- }
- return pocet;
- }
- int main() {
- int pole[5];
- char * retazec = NULL;
- za4_1 (pole, 2, 5);
- vypisPole (pole, 5);
- printf("%c\n",za4_2(35));
- retazec = za4_3(pole,5);
- printf("%s\n",retazec);
- // dealokacia dynamickeho pola z funkcie za4_3
- if(retazec!=NULL)
- free((void*)retazec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement