Created
January 17, 2014 12:46
-
-
Save Zulqurnain/0ac0e09dba3ca1877388 to your computer and use it in GitHub Desktop.
C++ code to take paragraph as an input from user and do the following: 1.count total number of character 2.count total number of spaces 3.count total number of string (are)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| using namespace std; | |
| int main(void){ // by zulqurnain jutt | |
| char arr[200]; // you can use pointer for longer strings | |
| cout<<"\n::Start Entering Your Paragraph Now::\n\t"; | |
| cin.getline(arr,200,'\n'); | |
| int i=0,j=0,NoofChars=0,Noofspaces=0,NoofStrings=0; | |
| for(;arr[i]!=0;i++,NoofChars++){ | |
| if(arr[i]==' '){ | |
| Noofspaces++; | |
| } | |
| if(arr[i]==' '&&((arr[i-1]>=65 &&arr[i-1]<=90)||(arr[i-1]>=97 && arr[i-1]<=122))){ | |
| NoofStrings++; | |
| } | |
| } | |
| NoofStrings++; // last word | |
| cout<<"Total Characters :=:"<<NoofChars<<"\nTotal Strings:=:"<<NoofStrings<<"\nTotal Spaces:=:"<<Noofspaces<<"\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment