Nishant Pandey
BAN USERIndian School of Mines
is it optimal code ??
#include<stdio.h>
int possibleValues(int val){
if(val==1)
return 1;
else if(val==6)
return 9;
else if(val==8)
return 8;
else if(val==9)
return 6;
else if(val==0)
return 0;
else
return -1;
}
int check_reversal(int a[],int size){
int start=0,i;
int end=size-1;
for(i=0;i<size;i++){
if(a[end]==possibleValues(a[start])){
}
else{
return 0;
}
start++;
end--;
}
return 1;
}
int main(){
int a[3]={8,1,8};
int b[4]={1,6,9,1};
int c[2]={8,8};
int d[4]={8,0,1,8};
int e[2]={2,1,2};
printf("%d",check_reversal(a,3));
printf("%d",check_reversal(b,4));
printf("%d",check_reversal(c,2));
printf("%d",check_reversal(d,4));
printf("%d",check_reversal(e,2));
return 0;
}
is PHP also dynamically typed then ???
- Nishant Pandey July 18, 2012how to write this type of question.
Please reply somebody
but you should include a condition when either i or j is equal to -1 and while loop breaks. In this condition it will simply copy the elements of another array to a.
- Nishant Pandey September 19, 2012