Write a single for statement to print the letters ‘A’ to ‘Z’ each 10 letters on a separate line.

28 views (last 30 days)
I am new to matlab this is my code can anyone help me
for array = [A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
count = 1:27;
if count > 10
fprintf('%s\n', array)
end
end

Answers (5)

Jan
Jan on 2 Dec 2016
Edited: Jan on 5 Dec 2016
fprintf('%c%c%c%c%c%c%c%c%c%c\n', 'A':'Z')
or:
fprintf([repmat('%c', 1, 10), '\n'], 'A':'Z')
In the 2nd version, you do not have to count manually in case of debugging or modifying the code.

Andrei Bobrov
Andrei Bobrov on 2 Dec 2016
a = 'A':'Z';
out = reshape([a,repmat(' ',1,mod(-numel(a),10))],10,[])';

Alexandra Harkai
Alexandra Harkai on 2 Dec 2016
count = 1;
for array = char(double('A'):double('Z')) % create character array from 'A' to 'Z'
fprintf('%s', array);
if count == 10
fprintf('\n');
count = 1; % start from the beginning of the line
else
count = count+1;
end
end
fprintf('\n');

Getinet Amare
Getinet Amare on 2 Sep 2018
allLetters=['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z'];
[dim,si]=size(allLetters);
count=0;
for i = 1:1:si
%fprintf('%s \t',strcat(allLetters(i),'1'))
fprintf('%s \t',allLetters(i))
for m = 1:1:si
ai=allLetters(i);
aj=allLetters(m);
%se=strcat(ai,aj,'1');
se=strcat(ai,aj);
fprintf('%s \t',se)
count=count+1;
end
end
fprintf('Total Number of letters %s ',count)

Getinet Amare
Getinet Amare on 2 Sep 2018
>> Excel()
output of the above source code
A AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ B BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ C CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT CU CV CW CX CY CZ D DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV DW DX DY DZ E EA EB EC ED EE EF EG EH EI EJ EK EL EM EN EO EP EQ ER ES ET EU EV EW EX EY EZ F FA FB FC FD FE FF FG FH FI FJ FK FL FM FN FO FP FQ FR FS FT FU FV FW FX FY FZ G GA GB GC GD GE GF GG GH GI GJ GK GL GM GN GO GP GQ GR GS GT GU GV GW GX GY GZ H HA HB HC HD HE HF HG HH HI HJ HK HL HM HN HO HP HQ HR HS HT HU HV HW HX HY HZ I IA IB IC ID IE IF IG IH II IJ IK IL IM IN IO IP IQ IR IS IT IU IV IW IX IY IZ J JA JB JC JD JE JF JG JH JI JJ JK JL JM JN JO JP JQ JR JS JT JU JV JW JX JY JZ K KA KB KC KD KE KF KG KH KI KJ KK KL KM KN KO KP KQ KR KS KT KU KV KW KX KY KZ L LA LB LC LD LE LF LG LH LI LJ LK LL LM LN LO LP LQ LR LS LT LU LV LW LX LY LZ M MA MB MC MD ME MF MG MH MI MJ MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ N NA NB NC ND NE NF NG NH NI NJ NK NL NM NN NO NP NQ NR NS NT NU NV NW NX NY NZ O OA OB OC OD OE OF OG OH OI OJ OK OL OM ON OO OP OQ OR OS OT OU OV OW OX OY OZ P PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ Q QA QB QC QD QE QF QG QH QI QJ QK QL QM QN QO QP QQ QR QS QT QU QV QW QX QY QZ R RA RB RC RD RE RF RG RH RI RJ RK RL RM RN RO RP RQ RR RS RT RU RV RW RX RY RZ S SA SB SC SD SE SF SG SH SI SJ SK SL SM SN SO SP SQ SR SS ST SU SV SW SX SY SZ T TA TB TC TD TE TF TG TH TI TJ TK TL TM TN TO TP TQ TR TS TT TU TV TW TX TY TZ U UA UB UC UD UE UF UG UH UI UJ UK UL UM UN UO UP UQ UR US UT UU UV UW UX UY UZ V VA VB VC VD VE VF VG VH VI VJ VK VL VM VN VO VP VQ VR VS VT VU VV VW VX VY VZ W WA WB WC WD WE WF WG WH WI WJ WK WL WM WN WO WP WQ WR WS WT WU WV WW WX WY WZ X XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ Y YA YB YC YD YE YF YG YH YI YJ YK YL YM YN YO YP YQ YR YS YT YU YV YW YX YY YZ Z ZA ZB ZC ZD ZE ZF ZG ZH ZI ZJ ZK ZL ZM ZN ZO ZP ZQ ZR ZS ZT ZU ZV ZW ZX ZY ZZ Total Number of letters 676>>
  1 Comment
Walter Roberson
Walter Roberson on 2 Sep 2018
It is not clear what your question or solution is?
The line indicates 676 solutions but you have printed out 702 solutions. Because each letter appears on its own as well as in pairs, you get 676+26 solutions.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!