Minggu, 28 Juli 2013

Contoh Program C++ (For Bersarang)

#include <iostream>
#include <conio.h>
#include <windows.h>
void setcolor(unsigned short color)
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(hCon,color);
}
int main()
{
    int n;
    setcolor(10);
    cout << "======================"<<endl;
    cout << "MasUkan BariS c0y = "; cin >> n;
    cout << "======================"<<endl;

    for (int a = 1; a <= n; a++)
    {
        int b = a - 1;
        for (int c = 1; c <= b; c++)
        {
            cout << " ";
        }

        b = (2 * n) - (2 * a - 1);
        for (int c = 1; c <= b; c++)
        {
            cout << "*";
        }
        cout << endl;
    }
getch();
}

Tidak ada komentar:

Posting Komentar