Rabu, 25 November 2009

Decision/Kondisi

Kondisi dalam program C++:
- for
- while
- do ... while
- if
- if ... else


>> FOR
#include<iostream.h>
void main()
{
int A, i, T;
T = 0;
for(i=1; i<=5; i=i+1)
{
cin>>A;
T=T+A;
}
cout<<T;
}



>> WHILE
#include<iostream.h>
void main()
{
int A, i, T;
T = 0;
i = 1;
while(i<=5)
{
cin>>A;
T=T+A;
i=i+1;
}
cout<<T;
}


>> DO ... WHILE
#include<iostream.h>
void main()
{
int A, i, T;
T = 0;
i = 1;
do
{
cin>>A;
T=T+A;
i=i+1;
}
while(i<=5);
cout<<T;
}


>> GAMBAR

















































Mata Kuliah Pemrograman OOP I
Kamis, 19 Nopember 2009

Tidak ada komentar: