Advertisements

Palindrom in C Programming

18 May

Palindrom merupakan sebuah kata, dimana huruf dari depan kebelakang dan dari belakang kedepan sama contoh : nababan, masam, kodok.

Fungsi void palindrom(char s[]) yang mengecek apakah suatu kata palindrom atau bukan. Jika terbukti palindrom, print output “Palindrom”, jika tidak “Bukan Palindrom”


#include<stdio.h>

void palindrom( char s[ ] )
{
int beda=0, maju, mundur;
for( mundur=0; s[mundur]!='\0'; mundur++ ) {
for( maju=0; maju<(mundur/2); maju++ ) {
if( s[maju] != s[--mundur] ) { beda++; break;
}
}

printf(" =>%s Palindrom\n",beda?"Bukan":"");
}

int main() {
char string[20];
printf(" Masukkan kata : ");
gets( string );
palindrom( string );
getchar();
return 0;
}

Advertisements

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: