matlab palindrome help

• Dec 13th 2012, 02:14 PM
unknown247
matlab palindrome help
i need to create a program that shows a 4 digit palindrome, make sure it can be divisible by 11 and show how many term is used,

so far i have

"for a = 1 : 9
for b = 0 : 9

results= a*1000+b*100+b*10+a;

if (rem(results,11)==0);
fprintf('The number %d is divisble by 11.\n ', results);
end

end
end "

and results are
"The number 1001 is divisble by 11.
The number 1111 is divisble by 11.
The number 1221 is divisble by 11.
The number 1331 is divisble by 11.
The number 1441 is divisble by 11.
The number 1551 is divisble by 11.
The number 1661 is divisble by 11.
The number 1771 is divisble by 11.
The number 1881 is divisble by 11.
The number 1991 is divisble by 11.
The number 2002 is divisble by 11.
The number 2112 is divisble by 11.
The number 2222 is divisble by 11.
The number 2332 is divisble by 11.
The number 2442 is divisble by 11."
ect

but i dont noe how to do that, i tried alot of ways, what am i doing wrong

thanks
• Jan 18th 2013, 02:32 PM
Naldi
Re: matlab palindrome help
You need to put a count function in this, like so
count=0

for a = 1 : 9
for b = 0 : 9

results= a*1000+b*100+b*10+a;

if (rem(results,11)==0);
fprintf('The number %d is divisble by 11.\n ', results);
count= count +1
end

end
end

fprintf('There are %d terms divisible by 11. \n' , count)

Greenwich matlab course work?? name the varible count something else as this is what i called it in my course work :P