March 12, 2013

Langsung cek programnya...




//mendeteksi palyndrom atau bukan
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char teks[50];

cout<<"Deteksi kalimat/kata ini : ";
cin.getline(teks,50); //'cin' untuk variabel string, & bisa membaca spasi

for(int i=0;i<teks[i];i++)teks[i]=tolower(teks[i]); //antisipasi kapital

int kar=strlen(teks); //'strlen' untuk menghitung karakter di variabel string
int x=0;
for(int i=0;i<kar/2;i++)
    {
    if(teks[i]==teks[kar-(i+1)])x++;
    }
   
if(x==kar/2)
cout<<endl<<"Hasil deteksi            : Palyndrom";
else
cout<<endl<<"Hasil deteksi            : Bukan Palyndrom";

getch();
}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Popular Post

- Copyright © welcome to Hakim's blog. -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -