Algoritma Pemrograman
#include <iostream>#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
char kata[100];
int bnyk;
cout<<"Kata: ";cin>>kata;
bnyk=strlen(kata); //digunakan untuk menghitung banyak nya karakter
//cout<<bnyk<<endl;
for(int i=0;i<bnyk;i++){
if(kata[i]!=kata[bnyk-1-i]){
cout<<"non-Palindrom";
i=bnyk;
}
else{
cout<<"Palindrom"; i=bnyk;
}
cout<<endl<<endl;
cout<<"Kata setelah di balik "<<endl;
for(bnyk=strlen(kata)-1;bnyk>=0;bnyk=bnyk-1){
cout<<kata[bnyk];
}
return 0;
}
}
2 comments
maacih gann
gan itu pake rekrusif kah.. makasi
EmoticonEmoticon