help!!
how to output
square like this
*****
*....*
*....*
*****
using for loop any idea
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <windows.h>
using namespace std;
int main(){
char star = '*';
string space = " ";
for(int i = 0; i < 5; i++)
cout << star;
cout << endl;
for(int i = 0; i < 1; i++)
cout << star << space << star;
cout << endl;
for(int i = 0; i < 1; i++)
cout << star << space << star;
cout << endl;
for(int i = 0; i < 5; i++)
cout << star;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <iomanip>
int main()
{
while ( true )
{
std::cout << "Enter a non-negative number (0 - exit): ";
unsigned int n = 0;
std::cin >> n;
if (!n ) break;
std::cout << std::endl;
for ( unsigned int i = 0; i < n; i++ )
{
const char asterisk = '*';
std::cout.fill( i % ( n - 1) == 0 ? asterisk : ' ' );
std::cout << asterisk << std::setw( n - 1 ) << asterisk << std::endl;
}
}
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.