M
Milutin_Popovski
//It occures is a number palindrom,
//For example 1221 is plandrom, and 1231 is not...
#include<stdio.h>
#include<malloc.h>
struct lista{
int val;
struct lista *next;
struct lista *prev;
};
int main(int argc , char *argv[]){
int i,j, k, n, m;
struct lista *first, *temp, *temp_prev, *old, *last;
if(argc!=2 || !chk(argv[1])){
printf("\nWrong argument");
return 1;
}
m=atoi(argv[1]);
first=malloc(sizeof(struct lista));
temp=first;
old=first;
temp->next=NULL;
temp->prev=NULL;
old->prev=NULL;
n=m;
while(m>0){
temp->val=m%10;
old=temp;
temp->next=malloc(sizeof(struct lista));
temp=temp->next;
temp->next=NULL;
temp->prev=old;
m=m/10;
}
temp=first;
printf("\n======================\n");
while(temp->next){
printf("%d ", temp->val);
temp=temp->next;
}
temp=temp->prev;
last=temp;
printf("\n======================\n");
while(temp){
printf("%d ", temp->val);
temp=temp->prev;
}
temp=first;
temp_prev=last;
while(temp){
if(temp->val!=temp_prev->val) goto izlaz;
printf("\n<%d><%d>", temp->val, temp_prev->val);
temp=temp->next;
temp_prev=temp_prev->prev;
}
printf("\n%d is palindrom", n);
return 0;
izlaz:
printf("\n%d is not a palindrom", n);
return 0;
}
int chk(char *c){
if(!isdigit(*c) && *c!='\0') return 0;
if(*c=='\0') return 1;
*c++;
chk(c);
}
//For example 1221 is plandrom, and 1231 is not...
#include<stdio.h>
#include<malloc.h>
struct lista{
int val;
struct lista *next;
struct lista *prev;
};
int main(int argc , char *argv[]){
int i,j, k, n, m;
struct lista *first, *temp, *temp_prev, *old, *last;
if(argc!=2 || !chk(argv[1])){
printf("\nWrong argument");
return 1;
}
m=atoi(argv[1]);
first=malloc(sizeof(struct lista));
temp=first;
old=first;
temp->next=NULL;
temp->prev=NULL;
old->prev=NULL;
n=m;
while(m>0){
temp->val=m%10;
old=temp;
temp->next=malloc(sizeof(struct lista));
temp=temp->next;
temp->next=NULL;
temp->prev=old;
m=m/10;
}
temp=first;
printf("\n======================\n");
while(temp->next){
printf("%d ", temp->val);
temp=temp->next;
}
temp=temp->prev;
last=temp;
printf("\n======================\n");
while(temp){
printf("%d ", temp->val);
temp=temp->prev;
}
temp=first;
temp_prev=last;
while(temp){
if(temp->val!=temp_prev->val) goto izlaz;
printf("\n<%d><%d>", temp->val, temp_prev->val);
temp=temp->next;
temp_prev=temp_prev->prev;
}
printf("\n%d is palindrom", n);
return 0;
izlaz:
printf("\n%d is not a palindrom", n);
return 0;
}
int chk(char *c){
if(!isdigit(*c) && *c!='\0') return 0;
if(*c=='\0') return 1;
*c++;
chk(c);
}