Exercise pertemuan 1 sampai 4

Pertemuan 1 Exercise

Write a C++ program that searches an unsorted array a[0:n-1] for the element x. If x exists in the array then return a position in the array, else return -1.


using namespace std;

int linearSearch(int a[], int key, int size)


int n;

for (n=0; n<size; ++n)


if (a[n] == key)


return n;



return -1;


int main()


int a[100], counter=0, total, i, search;

cout<<“Banyak angka yang ingin diinput: “;

cin>>total; cin.sync();cin.clear();

cout<<“Type each of “<<total<<” int now, each seperated by ENTER: “<<endl;



cin>>a[i]; cin.sync();cin.clear();


cout<<“Now enter the int to search: “<<endl;

cin>>search; cin.sync();cin.clear();



return 0;


The factorial function n! has value 1 when n   1 and value n*(n-1)! When n>1. Write both a recursive and an iterative C++ program to compute n!

Recursive :


using namespace std;

int faktorial(int n)


if(n < 1)


return 1;




return n * faktorial(n-1);



int main(){

int n;

cin >> n; cin.sync(); cin.clear();


cout << faktorial(n);


return 0;


Iterative :


using namespace std;

void main()


int i, N, iTampung=1;




iTampung = iTampung * i;


cout<<“Faktorial dari “<<N<<” adalah “<<iTampung;



Consider the function F(x) defined by “if x is even then F(x)=x/2; else F(x)=F(F(3x+1)).” Prove that F(x) terminates all integer x.


using namespace std;

int f(int x)


return x/2;


int main()


int angka;

cin>>integer; cin.clear(); cin.sync();

if(integer%2 == 0)









return 0;


Buatlah pseudocode untuk menghitung jumlah N bilangan ganjil yang pertama dengan menggunakan teknik rekursif!

1 Module jumlah(N)

2 if N == 1 then

3          result = 1

4 else

5          result = ( 2*N-1 ) + jumlah( N-1 )

6 end if

7 end module

Hitunglah Fungsi Kompleksitas untuk algoritma bilangan Fibonacci yang terdapat di pertemuan sebelumnya!

1 f1=0                                                                          (1)

2 f2=1                                                                          (1)

3 for i=1 to 8 do                                                       (N)

4   iFibo=f1+f2                                                           (N)

5   display ”Angka ke-”,i,” adalah ”,iFibo,NL    (N)

6   f1=f2                                                                       (N)

7   f2=iFibo                                                                 (N)

8 end for

Fungsi Kompleksitas f(N) : 5N + 2


106 thoughts on “Exercise pertemuan 1 sampai 4

  1. When I initially commented I clicked the “Notify me when new comments are added” checkbox and
    now each time a comment is added I get four emails with the same comment.
    Is there any way you can remove people from that
    service? Thanks a lot!

  2. Woah! I’m really loving the template/theme of this site. It’s simple, yet effective.
    A llot oof times it’s hard to get that “perfect balance” between usability and visual appearance.
    I must say that you’ve done a superb job with this. In addition,
    the bloig loads very fast for me oon Firefox.
    Outstanding Blog!

  3. My partner and I absilutely lve your blog and find alost all of
    your post’s to be exactly I’m looking for. Do you offer guest writers to
    write content in your case? I wouldn’t mind creating a post
    or elaborating on many of the subjects you write with regards to here.

    Again, awesome weblog!

  4. Just desire to say yyour article is aas amazing.
    The clarity in your post is simply excellent and i can assume
    you’re an expert on this subject. Fine with your
    permission let me to grab your feed to keep updated with forthcoming post.

    Thanks a million and please carry on the gratifying work.

  5. I leave a leave a response whenever I appreeciate a post on a website oor if I have something to valuable
    to contribute to the conversation. Usually it’s triggered by the sincerness communicated in the article
    I browsed. And after this post Exercise pertemuan 1 sampai 4 | My True Self.
    I was excited enough to drop a thought 🙂 I do have 2 questions
    for you if you do not mind. Is it simply me or does it
    give the impression like some of these remarks come across as if they are written by brain dead individuals?
    😛 And, if you are writing at other sites, I’d
    like to follow you. Could you make a list every onne of your community pages like your linkedin profile, Facebook page orr twitter feed?

  6. I am not sure where you are getting your information, but good topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for fantastic info I was looking for this information for my mission.

  7. hi!,I really like your writing very so much! share we be in contact more approximately your post on AOL?
    I require an expert on this house to solve my problem.
    Maybe that’s you! Looking forward to look you.

  8. Link exchange is nothing else except it is only placing the other person’s
    webpage link on your page at suitable place and other person will also do same in
    favor of you.

  9. Asking questions are really nice thing if you are not understanding something completely, except
    this article provides nice understanding yet.

  10. Today, I went to the beach front with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic
    but I had to tell someone!

  11. Excellent post. I was checking constantly this blog and I’m impressed!

    Very useful information specially the last part 🙂 I care for
    such info much. I was seeking this particular information
    for a very long time. Thank you and good luck.

  12. Excellent site. A lot of useful information here. I am sending it to some friends ans
    also sharing in delicious. And of course, thanks for
    your effort!

  13. Whats up are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get started and set up my own.
    Do you require any html coding expertise to make your own
    blog? Any help would be greatly appreciated!

  14. Hello, I believe your site might be having web browser compatibility problems.
    When I look at your site in Safari, it looks fine however when opening in I.E., it has some overlapping issues.
    I merely wanted to provide you with a quick heads up! Apart from that, wonderful site!

  15. I do believe all the ideas you’ve offered on your post.

    They’re very convincing and can definitely work. Nonetheless, the posts are very short
    for newbies. Could you please extend them a bit from next time?
    Thank you for the post.

  16. What’s Happening i’m new to this, I stumbled upon
    this I have discovered It positively useful
    and it has aided me out loads. I hope to contribute & assist different customers
    like its aided me. Good job.

  17. Hi would you mind letting me know which hosting company you’re
    utilizing? I’ve loaded your blog in 3 different internet browsers and I must say this
    blog loads a lot quicker then most. Can you suggest a good web hosting provider at a honest price?
    Many thanks, I appreciate it!

  18. Wonderful goods from you, man. I’ve understand your stuff previous to
    and you are just too great. I really like what you’ve acquired here, certainly like what you are stating and the
    way in which you say it. You make it entertaining and you still care for to keep it smart.

    I can’t wait to read much more from you. This is really a tremendous site.

  19. Excellent post. I used to be checking continuously this weblog and I am inspired!
    Extremely useful information specially the final section 🙂 I maintain such information much.

    I was seeking this particular info for a very
    long time. Thanks and good luck.

  20. May I just say what a comfort to discover someone who genuinely knows what they’re discussing
    on the net. You definitely realize how to bring a
    problem to light and make it important. More
    people should look at this and understand this side of your story.

    I was surprised that you’re not more popular because you certainly
    have the gift.

  21. Excellent weblog here! Also your website rather a lot up very
    fast! What host are you the usage of? Can I get your affiliate link to your host?
    I wish my site loaded up as quickly as yours lol

  22. I feel this is one of the most significant information for me.

    And i am glad studying your article. But wanna observation on some normal things, The
    web site style is ideal, the articles is truly great : D.
    Just right job, cheers

  23. I loved as much as you’ll receive carried out right
    here. The sketch is tasteful, your authored material stylish.
    nonetheless, you command get bought an edginess over that you wish
    be delivering the following. unwell unquestionably come more formerly
    again as exactly the same nearly a lot often inside case you
    shield this hike.

  24. Hello there, I found your blog by the use of Google at the same time as looking
    for a similar topic, your web site got here up, it appears good.
    I have bookmarked it in my google bookmarks.

    Hello there, just was alert to your blog through
    Google, and located that it is truly informative. I’m
    going to be careful for brussels. I will be grateful should you continue this in future.
    Numerous other folks will be benefited out of your writing.

  25. I truly love your blog.. Excellent colors & theme. Did you make this web site yourself?

    Please reply back as I’m looking to create my own website and want to learn where you got this from
    or just what the theme is named. Many thanks!

  26. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I’ll just
    sum it up what I had written and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog blogger but I’m still new to
    everything. Do you have any recommendations for newbie blog writers?
    I’d definitely appreciate it.

  27. I like the helpful information you provide in your articles.
    I will bookmark your blog and check again here regularly.

    I’m quite certain I’ll learn a lot of new stuff right
    here! Best of luck for the next!

  28. Howdy outstanding blog! Does running a blog like this take a great deal of work?
    I’ve very little understanding of computer programming however I
    was hoping to start my own blog soon. Anyway,
    if you have any ideas or tips for new blog owners please share.

    I know this is off topic nevertheless I simply wanted to ask.


  29. Hi would you mind sharing which blog platform you’re using?
    I’m looking to start my own blog in the near future
    but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your design and style seems
    different then most blogs and I’m looking for something completely unique.
    P.S Apologies for getting off-topic but I had to ask!

  30. Nice post. I was checking continuously this blog and I am impressed!
    Very helpful info particularly the last part
    🙂 I care for such info a lot. I was seeking this particular information for a long time.
    Thank you and good luck.

  31. Amazing blog! Do you have any recommendations for aspiring
    writers? I’m planning to start my own blog soon but I’m a little lost on everything.

    Would you suggest starting with a free platform like WordPress or go for a
    paid option? There are so many options out there that I’m completely confused ..
    Any ideas? Bless you!

  32. Simply desire to say your article is as amazing.
    The clearness in your post is simply nice and i could assume
    you’re an expert on this subject. Fine with your permission let me to grab your feed to keep
    updated with forthcoming post. Thanks a million and please continue the rewarding work.

  33. Pretty great post. I simply stumbled upon your weblog and
    wanted to say that I’ve really enjoyed browsing your weblog posts.
    After all I will be subscribing to your rss feed and I’m hoping you write once more soon!

  34. I am now not sure the place you are getting your information, but great
    topic. I must spend a while learning more or figuring out more.
    Thank you for magnificent information I was searching for this information for my mission.

  35. I’m not sure where you are getting your information, but great topic.
    I needs to spend some time learning more or understanding more.
    Thanks for great info I was looking for this information for
    my mission.

  36. Fantastic beat ! I would like to apprentice while you amend your website, how could i subscribe for a
    blog site? The account aided me a acceptable deal.
    I had been tiny bit acquainted of this your broadcast provided bright clear idea

  37. Hello, i think that i saw you visited my site thus i
    came to “return the favor”.I am attempting to find
    things to improve my website!I suppose its ok to use a
    few of your ideas!!

  38. What’s Happening i’m new to this, I stumbled upon this I’ve found It positively
    helpful and it has aided me out loads. I hope to contribute &
    help different customers like its helped me. Great job.

  39. For the reason that the admin of this site is working, no hesitation very soon it will
    be well-known, due to its quality contents.

  40. It’s the best time to make a few plans for the future and it is time to be happy.
    I have read this put up and if I could I desire to counsel you few attention-grabbing issues or advice.
    Perhaps you could write next articles referring to this article.
    I desire to read more issues about it!

  41. I feel that is among the so much vital information for me.
    And i am satisfied studying your article. However want to
    remark on some basic things, The web site taste is
    wonderful, the articles is in reality nice : D.
    Just right activity, cheers

  42. We are a group of volunteers and opening a new scheme in our community.
    Your website provided us with valuable information to work on. You have done a
    formidable job and our whole community will be
    thankful to you.

  43. I truly love your site.. Excellent colors & theme.
    Did you make this website yourself? Please reply back as I’m trying to create my own website and want to know where you got this from or
    what the theme is called. Appreciate it!

  44. Good day very cool website!! Man .. Beautiful ..
    Wonderful .. I’ll bookmark your website and take
    the feeds also? I’m happy to find numerous helpful
    info right here within the publish, we need work out extra strategies on this regard, thanks for sharing.
    . . . . .

  45. Fantastic beat ! I wish to apprentice at the same time
    as you amend your site, how could i subscribe for a weblog website?

    The account aided me a applicable deal. I have been a little bit familiar of this your broadcast provided bright transparent idea

  46. Greate post. Keep writing such kind of information on your site.
    Im really impressed by your site.
    Hey there, You’ve done a fantastic job. I’ll certainly digg it and in my view suggest
    to my friends. I am confident they will be benefited from this website.

  47. I’m really enjoying the design and layout of your blog.
    It’s a very easy on the eyes which makes it much more
    pleasant for me to come here and visit more often. Did
    you hire out a designer to create your theme? Exceptional work!

  48. Greetings from California! I’m bored to tears at work
    so I decided to check out your website on my iphone during lunch break.
    I enjoy the information you present here and can’t wait to take a look when I get home.
    I’m shocked at how quick your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyways, superb

  49. Hey I am so happy I found your website, I really found you by mistake, while I was
    researching on Aol for something else, Nonetheless I am here now and would just like to say thanks a lot for a incredible post and a all round
    entertaining blog (I also love the theme/design), I don’t have time to read it all at the
    moment but I have book-marked it and also added your RSS feeds, so when I
    have time I will be back to read a great deal more,
    Please do keep up the great jo.

  50. Pretty nice post. I just stumbled upon your blog and wished to say that I have really enjoyed browsing your blog posts.
    After all I will be subscribing to your feed and I hope you write again soon!

  51. Hey there! Someone in my Myspace group shared this site with us so I
    came to look it over. I’m definitely enjoying the information. I’m bookmarking
    and will be tweeting this to my followers!

    Exceptional blog and great design and style.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s