Algoritma membalik kata

26 11 2010

algoritma ini membalik satu kata, yang dimasukan ke dalam array, dengan konsep LIFO(last in first out)



#include <iostream.h>
#include <string.h>
int main()
{
char string[10];
int indeks;
cout <<“Masukan kalimat tanpa spasi: “;
cin >>string;
cout<<“setelah dibalik:”;
indeks = strlen(string) – 1 ;
while (indeks >= 0)
{
cout<<string[indeks];
indeks=indeks-1;
}
cout<<“\n”;
return 0;
}

ini hasilnya:

setelah di balik:

wassalam!


Actions

Information

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




%d bloggers like this: