Program mencetak elemen array rekursif

#include <cstdlib>
#include <iostream>

using namespace std;

int jumlah(int n) {
if(n==0) return (0);
else return (n-2 + jumlah(n-2));
}
void cetak(int n) {
if(n!=0){
cetak(n-2);
cout << n-2 << ” “; } 
} 
int main(int argc, char *argv[]) { 
int n = 10; cout << jumlah(n); 
cetak(n); 
system(“PAUSE”);
return EXIT_SUCCESS;
Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s