Advertisement
Adijata

broj zamijeni zbirom njegovih cifara

Sep 20th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int obrni(int broj)
  6. {
  7.     int novi=0;
  8.     while(broj!=0)
  9.     {
  10.         novi*=10;
  11.         novi+=broj%10;
  12.         broj/=10;
  13.     }
  14.     return novi;
  15. }
  16.  
  17. char* funkcija(char string[])
  18. {
  19.  
  20.     char* p=string;
  21.     char nova[80];
  22.     char *s=nova;
  23.     int br;
  24.     while(*p!='\0')
  25.     {
  26.  
  27.         if(*p>='0'&& *p<='9')
  28.  
  29.         {
  30.             br=0;
  31.  
  32.  
  33.             while(*p>='0'&& *p<='9')
  34.             {
  35.  
  36.                 br+=(*p-'0');
  37.                 p++;
  38.             }
  39.             br=obrni(br);
  40.  
  41.             while(br!=0)
  42.             {
  43.                 *s++=(char)(br%10+'0');
  44.                 br/=10;
  45.             }
  46.         }
  47.     else
  48.     *s++=*p++;
  49.     }
  50.     *s='\0';
  51.  
  52.      strcpy(string, nova);
  53.     return string;
  54. }
  55.  
  56. int main()
  57. {
  58.  
  59.     char rijec[88]= {"Neki broj 124, 90, 55555"};
  60.  
  61.     char nova[88];
  62.     char* p=nova;
  63.  
  64.     p=funkcija(rijec);
  65.  
  66.     while(*p!='\0')
  67.     {
  68.         printf("%c", *p++);
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement