Membuat Segitiga Siku-Siku Terbalik Di Visual C++
#include <iostream>
using
namespace
std;
int
main() {
int
i,j,n;
cout <<
"Masukkan nilai N: "
;
cin >> n;
for
(i=1;i<=n;i++) {
for
(j=i;j<=n;j++) {
cout <<
"*"
;
}
cout << endl;
}
return
0;
}
Perulangan Menggunakan FOR
#include <conio.h>
#include <stdlib.h>
void main()
{
randomize();
int data, mak, min,tot=0;
float rata;
for(int i=1;i<=5;i++)
{
data=random(100);
cout<<"Data masuk : "<<data<<endl;
if (i==1)mak=min=data;
else
{
if (mak<data)mak=data;
if (min>data)min=data;
}
tot=tot+data;
}
rata=tot/5;
cout<<"Rata-rata : "<<rata<<endl;
cout<<"Masimum : "<<mak<<endl;
cout<<"Minimum : "<<min<<endl;
getch();
}
CONTOH PERULANGAN DO... WHILE
#include <conio.h>
#include <stdlib.h>
void main()
{
randomize();
int data, mak, min,tot=0,i=1;
float rata;
while(i<=5)
{
data=random(100);
cout<<"Data masuk : "<<data<<endl;
if (i==1)
mak=min=data;
else
{
if (mak<data)
mak=data;
if (min>data)
min=data;
}
tot=tot+data;
i++;
}
rata=tot/5;
cout<<"Rata-rata : "<<rata<<endl;
cout<<"Masimum : "<<mak<<endl;
cout<<"Minimum : "<<min<<endl;
getch();
}