+ 1
The symbol s and the natural numbers n,m are given. n and m are odd numbers.print a rectangular frame and plus inside
The symbol s and the natural numbers n, m are given. n and m are odd numbers. Print a rectangular frame of s characters with size n x m, and a plus inside.
11 Answers
0
else if(i==N/2 || j==M/2 )cout << s;
Add this condition also..Ruslan
+ 1
thank you!!!
+ 1
so,i need “X” inside rectangular frame of s characters with size n x m
0
Post your try..
0
#include <iostream>
using namespace std;
int main() {
char s;
cin » s;
int N,M;
cin » N»M;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (i == 0 || i == N - 1 ) cout « s;
else if (j == 0 || j == M - 1) cout « s;
else cout « " ";
}
cout « endl;
}
}
0
Your program works fine but use << for in cin, cout. (double less than symbols, the symbol you are using is wrong one).
And adjust output as charecter width if you need..
Edit : Ruslan
#include <iostream>
using namespace std;
int main() {
char s;
cin >> s;
int N,M;
cin>> N>>M;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (i == 0 || i == N - 1 ) cout << s;
else if (j == 0 || j == M - 1) cout <<s;
else cout << "O";
}
cout <<endl;
}
}
0
You have to use >> and << like Jayakrishna🇮🇳 said. If you save your code in code Playground and link it here it is easier to help you. Please clarify what is meant by "a plus inside"
0
The symbol s and the natural numbers n, m are given.
n and m are odd numbers.
Print a rectangular frame of s characters with size n x m, and a plus inside.
0
this code just create rectangle frame , i need a rectangular fram of s characters with size n x m, and plus inside
0
Example:
Input:
# 7 5
Conclusion:
#####
# # #
# # #
#####
# # #
# # #
#####.
0
It's your wish. Adding space looks like something missing as it's width looks like is less than charecter.(it's a lower letter). So if you add anything other than space you can see clearly that it's getting correct or not..