Jumat, 24 Juni 2011

Recursive Iterative Programs


Algorithm:

Declaration:

x, i    : integer
Descripyion:
Rekursif
read x
if (x >= 1) then
rekursif (x - 1)
write x
end if
end

Iteratif
read x
for i <- 1 to x do
write i
end for
end

Program:

  1. #inc
  2. #include <iostream.h>
  3. lude <conio.h>
  4. int iteratif(int x){
  5. for(int i=1; i<=x; i++){
  6. cout<<i;
  7. }}
  8. int rekursif(int x){
  9. if(x>=1){
  10. rekursif(x-1);
  11. cout<<x;
  12. }
  13. }
  14. int main(){
  15. int x;
  16. cout<<"Inputkan angka : ";
  17. cin>>x;
  18. cout<<endl;
  19. cout<<"Iteratif:  ";
  20. iteratif(x);
  21. cout<<endl;
  22. cout<<"Rekursif:  ";
  23. rekursif(x);
  24. getch();
  25. return 0;
  26. }
Aril Enggal's Web Developer

Morbi aliquam fringilla nisl. Pellentesque eleifend condimentum tellus, vel vulputate tortor malesuada sit amet. Aliquam vel vestibulum metus. Aenean ut mi aucto.

Tidak ada komentar:

Posting Komentar