Q.1.
n=”hello”
h
he
hel
hell
hello
//n="hello"
//h
//he
//hel
//hell
//hello
#include<iostream>
#include<string>
using namespace std;
int main()
{
string n="Hello";
cout<<"string is "<<n<<endl;
for(int i=0;i<n.size();i++)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
//Using user input
cout<<"Enter any string ";
cin>>n;
cout<<"string is "<<n<<endl;
for(int i=0;i<n.size();i++)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
return(0);
}
//n="hello"
//h
//he
//hel
//hell
//hello
#include<iostream>
#include<string>
using namespace std;
int main()
{
string n="Hello";
cout<<"string is "<<n<<endl;
for(int i=0;i<n.size();i++)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
//Using user input
cout<<"Enter any string ";
cin>>n;
cout<<"string is "<<n<<endl;
for(int i=0;i<n.size();i++)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
return(0);
}
//n="hello" //h //he //hel //hell //hello #include<iostream> #include<string> using namespace std; int main() { string n="Hello"; cout<<"string is "<<n<<endl; for(int i=0;i<n.size();i++) { for(int j=0;j<=i;j++) { cout<<n[j]; } cout<<endl; } //Using user input cout<<"Enter any string "; cin>>n; cout<<"string is "<<n<<endl; for(int i=0;i<n.size();i++) { for(int j=0;j<=i;j++) { cout<<n[j]; } cout<<endl; } return(0); }
Q.2.
n=”hello”
hello
hell
hel
he
h
//n="hello"
//hello
//hell
//hel
//he
//h
#include<iostream>
#include<string>
using namespace std;
int main()
{
string n="Hello";
cout<<"string is "<<n<<endl;
for(int i=n.size()-1;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
//Using user input
cout<<"Enter any string ";
cin>>n;
cout<<"string is "<<n<<endl;
for(int i=n.size()-1;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
return(0);
}
//n="hello"
//hello
//hell
//hel
//he
//h
#include<iostream>
#include<string>
using namespace std;
int main()
{
string n="Hello";
cout<<"string is "<<n<<endl;
for(int i=n.size()-1;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
//Using user input
cout<<"Enter any string ";
cin>>n;
cout<<"string is "<<n<<endl;
for(int i=n.size()-1;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
cout<<n[j];
}
cout<<endl;
}
return(0);
}
//n="hello" //hello //hell //hel //he //h #include<iostream> #include<string> using namespace std; int main() { string n="Hello"; cout<<"string is "<<n<<endl; for(int i=n.size()-1;i>=0;i--) { for(int j=0;j<=i;j++) { cout<<n[j]; } cout<<endl; } //Using user input cout<<"Enter any string "; cin>>n; cout<<"string is "<<n<<endl; for(int i=n.size()-1;i>=0;i--) { for(int j=0;j<=i;j++) { cout<<n[j]; } cout<<endl; } return(0); }