Advertisement
sellmmaahh

OR-Broj Duplih Slova

Sep 6th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int length (char *s) {
  6.     int d=0;
  7.     while (*(s++)!='\0') d++;
  8.     return d;
  9. }
  10. int JeLiMalo (char c) {
  11.     if (c>='a' && c<='z') return 1;
  12.     return 0;
  13. }
  14. int JeLiVeliko (char c) {
  15.     if (c>='A' && c<='Z') return 1;
  16.     return 0;
  17. }
  18.  
  19. int BrojDuplihSlova(char *s) {
  20.     int slova[27], brojac=0, duzina=length(s), i;
  21.     for(i=0; i<27; i++) slova[i]=0;
  22.  
  23.     for (i=0; i<duzina; i++) {
  24.             if (JeLiMalo(s[i])) slova[s[i]-'a']++;
  25.             else if (JeLiVeliko(s[i])) slova[s[i]-'A']++;
  26.     }
  27.     for (i=0; i<27; i++) {
  28.             if (slova[i]==2) brojac++;
  29.     }
  30.     return brojac;
  31. }
  32.  
  33. int main () {
  34.     char s[]="Selma je bila ovdje.";
  35.     printf("Broj duplih slova: %d", BrojDuplihSlova(s));
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement