Friday, 11 July 2014

A Simple C++ program based on strings

Aim of this program is...when a user gives input consisting of letters followed by numbers...eg: a2b3 then output should be aabbb
  1 #include<iostream> 
  2 #include<ctype.h> 
  3 using namespace std;
  4 int main() 
  5 { 
  6     char str[50],a;
  7     cout<<"Enter a string: "; 
  8     cin>>str; 
  9     int len=strlen(str),rep,j=0; 
 10     int i=len/2;
 11      
 12     while(i) 
 13     { 
 14          
 15         a=str[j]; 
 16         rep=(str[j+1])-'0'; 
 17          
 18         while(rep) 
 19         { 
 20             cout<<a; 
 21             rep--; 
 22         } 
 23         i--;j=j+2; 
 24     } 
 25      
 26     return 0;
 27 }
Have a nice day!!

No comments:

Post a Comment