Advertisement
Dimitrija

Laboratoriski 8 - 5 SP ALT

Dec 26th, 2020 (edited)
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #define MAX 1000
  5.  
  6. void letterFrequency (char *text, char letter) {
  7.  
  8.     int i;
  9.     float small=0,BIG=0;
  10.     if (isupper(letter)){
  11.         letter = tolower(letter);
  12.     }
  13.  
  14.  
  15.     for (i=0;i<strlen(text);i++){
  16.  
  17.         if (letter == *(text+i)){
  18.             small++;
  19.         }
  20.         if (toupper(letter) == *(text+i)){
  21.             BIG++;
  22.         }
  23.  
  24.     }
  25.     float all = strlen(text)+1;
  26.     printf("%c -> %.3f%%\n",letter,small/all*100);
  27.     printf("%c -> %.3f%%",toupper(letter),BIG/all*100);
  28.    
  29.  
  30.  
  31.  
  32. }
  33.  
  34. int main(){
  35.  
  36.  
  37.     char niza[MAX];
  38.     char c;
  39.     scanf("%[^\n]",niza);
  40.     getchar();
  41.     scanf("%c",&c);
  42.  
  43.     letterFrequency (niza,c);
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement