U E D R , A S I H C RSS

UpgradeC++/과제1

1. 피라미드 & 역피라미드 & 마름모

1.1. 재화

~cpp 
#include<iostream>
#include<string>
using namespace std;
int main()
{
	//피라미드
	for(int i=0; i<5; i++)
	{
		string space(4-i,' ');
		cout << space;
		string star(2*i+1,'*');
		cout<<star;
		cout<<endl;
	}
	cout<<"--------------------------------------------"<<endl<<endl;	
	//역피라미드
	for( i=0; i<5; i++)
	{
		for(int k =0 ; k< i ; k++)
			cout<<" ";
		for(int j=0;j<9-2*i; j++)
			cout<<"*";
		
		cout<<endl;
	}
	cout<<"--------------------------------------------"<<endl<<endl;	
	
	//마름모
	int size = 11;
	for(i=0; i<size; i++)
	{
		string space(abs(size/2-i),' ');
		cout << space;
		if(i < size/2+1)
		{
			for(int j=0; j< (2*i+1) ; j++)
				cout<<"*";
		}
		else
		{
			for(int j=0; j< size-2*(i-size/2) ; j++)
				cout<<"*";
		}
		cout<<endl;
	}
	return 0;
}

1.2. 응택

~cpp 
#include <iostream>
using namespace std;
int main()
{
	cout << "숫자를 입력하세요(행의 개수) = ";
	int row;
	cin >> row;
// 피라미드&역피라미드
	for (int i=0;i<row;i++)
	{
		for (int j=i+1;j<row;j++)
			cout << " ";
		for (j=2*i+1;j>0;j--)
			cout << "*";
		for (j=i+1;j<row;j++)
			cout << " ";
		for (j=i;j>0;j--)
			cout << " ";
		for (j=2*i+1;j<2*row;j++)
			cout << "*";
		cout << endl;
	}
// 마름모
	for (i=0;i<row;i++)
	{
		for (int j=abs(row-i*2-1)/2-1;j>=0;j--)
			cout << " ";
		for (j=abs(row-i*2-1);j<row;j++)
			cout << "*";
		cout << endl;
	}
// 삼각형 테스트
	for (i=0;i<row;i++)
	{
		for (int j=i+1;j>0;j--)
			cout << "*";
		for (j=i;j<row;j++)
			cout << " ";
		for (j=i;j<row;j++)
			cout << "*";
		for (j=2*i+1;j>0;j--)
			cout << " ";
		for (j=i;j<row;j++)
			cout << "*";
		for (j=i;j<row;j++)
			cout << " ";
		for (j=i+1;j>0;j--)
			cout << "*";
		cout << endl;
	}
	return 0;
}
올 대단한걸..^^ 잘해쓰~ 앞으로도 계속 열심히..조재화

1.3. 재선

~cpp 
#include <iostream>  
#include <string>  
using namespace std;  
  
int main()  
{ 
    int row;  
    cin >> row;  
    int j = 0;  
 
    for(j = 0; j < row; j++)                        // 피라미드  
    { 
        string spaces(row-(j+1), ' ');  
        string asterisks(j*2+1, '*');  
        cout << spaces;  
        cout << asterisks;  
        cout << "\n";  
    }  
    cout << "\n";  
 
    for(j = row - 1; j >= 0; j--)           // 역피라미드  
    {  
        string spaces(row-(j+1), ' ');  
        string asterisks(j*2+1, '*');  
        cout << spaces;  
        cout << asterisks;  
        cout << "\n";  
    } 
    cout << "\n";  

    int middle = row / 2 + 1;                               // 마름모 

    for (j = 0; j < middle; j++) 
    { 
        string spaces(middle-(j+1), ' '); 
        string asterisks(j * 2 + 1, '*'); 
        cout << spaces; 
        cout << asterisks; 
        cout << "\n"; 
    } 

    for (j = middle-1; j  > 0; j--) 
    { 
        string spaces(row-(middle+j-1), ' ');  
        string asterisks(j*2-1, '*');  
        cout << spaces;  
        cout << asterisks;  
        cout << "\n";  
    } 
     
    return 0; 
} 

1.4. 보담

~cpp 
#include <iostream>
using namespace std;

int main()
{
	char star = '*';
	char space = ' ';
	int number;
	int numberu;
	int dia;
//피라미드
	cout << "숫자를 입력하세요 : ";
	cin >> number;
	int i, j;
	for (i=0; i<number; i++)
	{
		for (j=number-i-1; j>0; j--)
			cout << space;
		for (j=0; j<=i*2; j++)
			cout << star;
		cout << "\n";
	}
//역피라미드
	cout << "숫자를 입력하세요 : ";
	cin >> numberu;
	for (i=0; i<=numberu; i++)
	{
		for (j=0; j<i; j++)
			cout << space;
		for (j=numberu+4; j>i*2; j--)
			cout << star;
		cout << "\n";
	}
	return 0;
}	

1.5. 슬이

~cpp 
난 잠시 바빠서 그날 한건만 올려놓고 곧 수정할께 ㅋㅋ 자료구조 숙제의 압박 ㅋㅋ 니네가 도와줘 ㅋㅋㅋ
#include <iostream>
#include <string>
using namespace std;

void main()
{/*
 for(int row =0; row <5 ; row ++)
 {
  for (int col = 4-row ; col >0 ; col--)
  {
   cout <<" ";
  }
  for(int col2=1; col2 <=2*row +1 ; col2++){
   cout <<"*";
  }
  cout << endl;
 }
 //cout << endl;

 int temp =9;
 
 for(int row2 =0; row2 <5 ; row2++)
 {
  for(int col3 =0; col3<row2 ; col3++)
  {
   cout << " ";
  }
  for(int col4=temp ;col4>0;col4--)
  {
   cout << "*";
  }
  temp = temp-2;
  cout << endl;
 }
 cout << endl;*/
int temp =9;
 for(int irow =0 ; irow <10; irow++)
 {
  for(int icol=0; icol <(abs(5-irow)) ; icol++)
  {
   cout <<"=";
  }
  for(int icol2=0; icol2 <=2*irow +1 ; icol2++){
   cout <<"*";
  }
  for(int icol3=temp ;icol3>0;icol3--)
  {
   cout << "*";
  }
   
  temp=temp-2;    
  cout << endl;
 }
}
마름모는 우선안됨 ㅋㅋ
마른모 얼른해서 올려봐~^^ 조재화

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0100 sec