Thursday, 27 October 2011

Program C++ Membuat Bintang Persegi

Program C++ Membuat Bintang Persegi. This tutorial continues on C + +, here we will learn how to make a square of stars in C + +. There are several requirements that should I give here. Square width must be between 1 and 20. Here we use a for statement to print the stars. Then in the statement for, we added another if statement, the point in order to determine the index into any number of stars will be printed later.

Actually this is a weekly task given to me professor, but I decided to share them with friends as well.


#include <iostream.h>
#include <conio.h>

int main()
{
 int ukuran;

 do
 {
  cout<<"Masukkan ukuran persegi: ";
  cin>>ukuran;
 }while(ukuran<1||ukuran>20);

 cout<<endl;

 for(int i=1; i<= ukuran; i++)
 {
  for(int j=1; j<=ukuran; j++)
  {
   if(i==1||j==1||i==ukuran||j==ukuran)
   {
    cout<<"*";
   }
   else
   {
    cout<<" ";
   }
  }
  cout<<endl;
 }

 getch();
 return 0;
}

1 comment:

Haedir Gokil said...

ini nih yang gue cara, thanks banget bro

http://onthe7.blogspot.com

Post a Comment