Student Portfolio >> Index >> Coding >> Exercise 7
#include <iostream.h>
#include <math.h>
#include <string.h>
const int SIZE = 100;
int countcaps(char []);
int main()
{ char sentence[SIZE];
int count;
cout<<"Enter A Small Sentence With Capitals: ";
cin.getline(sentence, SIZE);
count = countcaps(sentence);
cout<<"\nNumber of capital letters is "<<count<<endl;
return 0;
}
int countcaps(char anystring[])
{
int i, caps=0;
for(i=0;i<strlen(anystring);i++)
if (anystring[i] >= 'A' && anystring[i]<='Z')
caps++;
return caps;
}
<< Back Forward >> |
Copyright 2005 Kerstin Kegel