Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int znaki(char txt[], int i)
  7. {
  8.     if(txt[i]=='\0')
  9.         return i;
  10.     else
  11.         return znaki(txt, i+1);
  12. }
  13.  
  14. int znakiBezSpacji(char txt[], int i, int j)
  15. {
  16.     if(txt[i]=='\0')
  17.     {
  18.         return i-j;
  19.     }
  20.     else
  21.     {
  22.         if(txt[i]==32)
  23.         return znakiBezSpacji(txt, i+1, j+1);
  24.         else
  25.         return znakiBezSpacji(txt, i+1, j);
  26.     }
  27.  
  28. }
  29.  
  30. void wypiszTekst(char txt[], int i)
  31. {
  32.     if(txt[i]=='\0')
  33.         return;
  34.     cout<<txt[i];
  35.     wypiszTekst(txt, i+1);
  36. }
  37.  
  38. void tekstWspak(char txt[], int i)
  39. {
  40.     if(txt[i]=='\0')
  41.         return;
  42.     tekstWspak(txt, i+1);
  43.     cout<<txt[i];
  44. }
  45. int main()
  46. {
  47.     char txt[100];
  48.     cout<<"Podaj tekst: "<<endl;
  49.     cin.getline(txt, 100);
  50.     cout<<"Liczba znakow: "<<endl;
  51.     cout<<znaki(txt, 0);
  52.     cout<<'\n'<<"Liczba znakow bez spacji: "<<endl;
  53.     cout<<znakiBezSpacji(txt, 0, 0);
  54.     cout<<'\n'<<"Tekst: "<<endl;
  55.     wypiszTekst(txt, 0);
  56.     cout<<'\n'<<"Tekst wspak:  "<<endl;
  57.     tekstWspak(txt, 0);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement