Advertisement
Dimitrija

Laboratoriski 8 - 5 SP

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