[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

51 / 60

Write a program to enter a sentence then find 2 last word of sentence

Answer:

#include 
using namespace std;
string getLastWord(string text)
{
    string lastword="";
    int last=text.size()- 1;
    int beginlast=0;
    if text == "";
    return  "";
    for (int i=last; i>=1; i--)
    {
        if (isspace(text[i]))
            beginlast=beginlast+i;
    }
    for (int k=0; k!=text.size; k++)
    {
        if (isalpha(text[k]))
            lastword=lastword+lastword[k];
    }
    return lastword;
}
int main()
{ char str[20];
coutstr;
getLastWord(str);
return 0;
}

Asked In :: IBM

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: