Please solve this question

R

reepakmajhi.com

Write a c++ program to display the following?

# # # # #

K V Jharsuguda

# # # # #
 
B

Bo Persson

Write a c++ program to display the following?

# # # # #

K V Jharsuguda

# # # # #

#include <iostream>

int main()
{
std::cout << "the following?";
}


Bo Persson
 
J

Juha Nieminen

Write a c++ program to display the following?

# # # # #

K V Jharsuguda

# # # # #

int main()
{
const char* str =
"# # # # #\n"
"\n"
" K V Jharsuguda\n"
"\n"
"# # # # #\n";

std::cout << str;
}
 
O

osmium

Write a c++ program to display the following?

# # # # #

Look at the output; it prints a blob of characters, then prints another blob
and does this exactly 5 times. Since the number is constant and known when
the program is written, it strongly suggests a for loop. Now look at the
individual blobs. Each blob starts with a # and is followed by
approximately 11 spaces. We can't tell for sure about the last blob, but
assuming it is will not violate anything in the problem statement. again,
everything is known in advance, which suggests another for loop. You could
use nested for loops or have the outermost for call a function. The latter
approach will "hide" the nested aspect and may be easier to understand.
 
J

James Kanze

#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
int main() {

std::istringstream input_stream(
"23 20 20 20 20 20 20 20 20 20 20 20 23 20 20 20"
"20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
"20 20 20 20 20 23 20 20 20 20 20 20 20 20 20 20"
"20 23 0a 0a 20 20 20 20 20 20 20 20 20 20 4b 20"
"56 20 4a 68 61 72 73 75 67 75 64 61 0a 0a 23 20"
"20 20 20 20 20 20 20 20 20 23 20 20 20 20 20 20"
"20 20 20 20 20 20 23 20 20 20 20 20 20 20 20 20"
"20 20 23 20 20 20 20 20 20 20 20 20 20 20 23 0a" );
input_stream.flags(std::ios::hex | std::ios::skipws);
copy(
std::istream_iterator<unsigned>( input_stream ),
std::istream_iterator<unsigned>( ),
std::eek:stream_iterator<char>( std::cout ));
return 0;
}

Did you actually try it? All you're doing is outputting your
string literal.

The obvious answer is something like:
std::cout
<< "# # # # #\n"
" K V Jharsuguda\n"
"# # # # #"
<< std::endl ;
But the answer is so obvious I suspect that tbe original poster
has some other additional requirements which he's chosen to hide
from us.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top