/* *copyright (c) 2014 Yantai University School of computer *all rights reserved. * Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp *: Yang Hanning * Completion Date: December 8, 2014 * Version number: v1.0 * * Problem Description: Count the number of occurrences per letter * Input Description: No * program output: The number of each letter appears */#inclu De<iostream>using namespace Std;int Main () { char str[100]= {"My name is yanghanning and I live in Chengdu"};
int i,a[26]= {0}; for (i=0; str[i]!= '; ++i) { if (str[i]>= ' a ' &&str[i]<= ' z ') a[str[i]-' a ']++; } The number of lowercase letters in cout<< "\" "<<str<<" \ "is:" <<endl; for (i=0; i<26; ++i) cout<< "Letters" <<char (i+97) << "occurrences are:" << " <<a[i]< < "Times" <<endl; return 0;}
Count the number of occurrences of each letter in a sentence