Question

Use a for loop to print out the string with spaces in between each letter code.cpp New 1 #include iostream> 2 #include <strin

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str = "Hello World";
    for (int i = 0; i < str.length(); ++i) {
        cout << str[i] << " ";
    }
    cout << endl;
    return 0;
}

Process finished with exit code 0


\color{blue}Please\;let\;me\;know\;if\;you\;have\;any\;doubts\\ Please\;upvote\;this\;answer.\;\;Thanks!!

Add a comment
Know the answer?
Add Answer to:
Use a for loop to print out the string with spaces in between each letter code.cpp...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are to implement a MyString class which is our own limited implementation of the std::string...

    You are to implement a MyString class which is our own limited implementation of the std::string Header file and test (main) file are given in below, code for mystring.cpp. Here is header file mystring.h /* MyString class */ #ifndef MyString_H #define MyString_H #include <iostream> using namespace std; class MyString { private:    char* str;    int len; public:    MyString();    MyString(const char* s);    MyString(MyString& s);    ~MyString();    friend ostream& operator <<(ostream& os, MyString& s); // Prints string    MyString& operator=(MyString& s); //Copy assignment    MyString& operator+(MyString&...

  • I have to write a loop that moves the content of the dynamic array to the...

    I have to write a loop that moves the content of the dynamic array to the static array but I can't seem to figure it out. Exit Full Screen code.cpp New 1 #include <iostream> 3 using namespace std; 4 5 int main) 6 int *ptr 7 ptr -new int[5]; 8 int arr[5]; 9int x; 10 cin >> x; 11 for( int í = 0; 1 < 5; 1++) // initialization 12 13 ptr[i] x; = 14 for O//your code goes...

  • Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass...

    Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...

  • In C++ Write a program that will read a string, call 2 functions to modify the...

    In C++ Write a program that will read a string, call 2 functions to modify the string, and then print the final result. The first function should take a string parameter and return the string without any vowels. The second function should take a string and double every letter (which should be all consonants at this point). Be sure to: You must use more than [ ] and at You must use erase, insert, replace, find, and/or substr to make...

  • Fix the code to print the result[] array properly: 1 #include <iostream> 2 3 using namespace...

    Fix the code to print the result[] array properly: 1 #include <iostream> 2 3 using namespace std; 4 5 void printArray(int array 7 for(inti= 0: i < 2;i++) cout くく array[i] << " ". 10 12 int mainO 13 14 int firstArray[2]10,20}; 16 int resultr21 17 int x; 18 19 II take input for second array 20 cin >>x 21 secondArray[0]-x; 22 secondarrayL1」-X+15 ; // Add elements 23 24 result0]- firstArray[0] + secondArray [0]; 25 result [1]- firstArray[1] + secondArray[1];...

  • when i run it is still be "false" i don't know why. could you help me...

    when i run it is still be "false" i don't know why. could you help me fix it and tell me which part is wrong??? specific answer is better thanks!!! Problem 6: (4 pts): Write a function that takes as an input parameter a string. It should return a Boolean value indicating whether the string is a palindrome or not. INPUT: “mom"->true “palindrome”->false “amanaplanpanama"->true 3 #include <iostream> #include <string.h> I using namespace std; string function(string str); int main() { function("palindrome");...

  • 15.6: Fix the code to print the count from 1 to x (to loop x times)...

    15.6: Fix the code to print the count from 1 to x (to loop x times) #include <iostream> // include the header file using namespace std; void count(int x){    for(int i=1; i<=x; i++){ cout<<x; } } int main(){    int x,i;    cin >> x; count(x);    return 0; } 15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x" #include <iostream> // include the header file using namespace std; int main(){...

  • use c++ 2. Make only one change to the program below so that the current output...

    use c++ 2. Make only one change to the program below so that the current output changes to the desired output. Program Current output Desired output include Kio stream> include <strin using namespace std; int main string s1 Hello World" for (int i 0 i sl. size i++) for (int j 0 j<i j++) cout cout s1 [i] endl return 0;

  • I need help with this program. C++ Given a string, compute recursively (no loops) a new...

    I need help with this program. C++ Given a string, compute recursively (no loops) a new string where all appearances of "pi" have been replaced by "3.14". It should enter a string like: (xpix)--> and print out " x3.14x" (pi)--> and print out " 3.14p" (pipi)--> and print out " 3.143.14" This is what I have so far... #include<iostream> #include<string> using namespace std; string changePi(string str) { string left; if(str.length() < 2) return str; if(str.substr(0, 1).compare("pi")) return "3.14" + changePi(str.substr(2));...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT