Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Sviluppare una function C che, dati come parametri di input un array di char e il suo
- size, determina e restituisce come parametro di output il carattere più frequente.
- **/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- char letteramag(int n, char s[]) {
- char alfabeto[] = "abcdefghilmnopqrstuvz";
- int i,j;
- int occor[21];
- for(i = 0; i < 21; i++)
- occor[i] = 0;
- for(i=0;i<n;i++)
- {
- s[i]=tolower(s[i]);
- }
- for(i=0;i<n;i++) {
- for (j=0;j<21;j++) {
- if(s[i] == alfabeto[j]) {
- occor[j]++;
- }
- }
- }
- int max=occor[0]; int j_max=0;
- for (j=0;j<21;j++) {
- if(occor[j]>max)
- {
- max=occor[j];
- j_max=j;
- }
- }
- return alfabeto[j_max];
- }
- int main() {
- char s[]="Pochi sforzan quel gambo di vite";
- int n;
- n=strlen(s);
- int a;
- a=letteramag(n,s);
- printf("%c",a);
- }
Advertisement
Add Comment
Please, Sign In to add comment