Algoritma
1. 1. Analisinya
Membuat bintang membentuk diamond
2. Identifikasi
Input :
masukkan batas bintang
Output :
Membentuk diamond
C++ nya :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, k;
cout<<"Input Batas Bintang: ";
cin>>k;
for(i=1;i<=k;i++)
{
for(j=1;j<=k-i;j++)
cout<<" ";
for(j=1;j<=i;j++)
cout<<"* " ;
cout<<endl;
}
k=k-1;
for(i=1;i<=k;i++)
{
for(j=1;j<=i;j++)
cout<<" ";
for(j=1;j<=k-i+1;j++)
cout<<"* ";
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, k;
cout<<"Input Batas Bintang: ";
cin>>k;
for(i=1;i<=k;i++)
{
for(j=1;j<=k-i;j++)
cout<<" ";
for(j=1;j<=i;j++)
cout<<"* " ;
cout<<endl;
}
k=k-1;
for(i=1;i<=k;i++)
{
for(j=1;j<=i;j++)
cout<<" ";
for(j=1;j<=k-i+1;j++)
cout<<"* ";
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
#Screenshot :
Tidak ada komentar:
Posting Komentar