10 Challenging Star Pattern Programs in C - Interview Mantra
10 Challenging Star Pattern Programs in C - Interview Mantra
25 Votes Computer languages are not as easy as human languages, they need you to become a computer yourself, think like a computer and write an algorithm. Computer programs are fun if you take them up as a challenge, as unsolved puzzles. There is lot of fun in taking up the challenge, understanding the problem, writing an algorithm, writing a program and most importantly running the program and obtaining required output. Here are few challenging C program questions for you. Lets see how many of them you would be able to write without seeing the program solution given below. These questions are to print patterns using asterisk(star) character. Comment below if you have tougher pattern questions.
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
1/25
2/29/12
***** *** * *** *****
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
2/25
2/29/12
Program:
/ Ti i asml mro-mg o argtagetinl * * hs s ipe irriae f ih nl rage / #nld icue itmi( { n an) ca pn ='' hr rt *; iti j ns=4 s n , , o , ; fr( =1 i< 5 i+ {fr( =ns s> 1 s- { / Saigfco o i ; = ; +) o s o; = ; -) / pcn atr pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) pit(%c,pn) rnf"2" rt; } pit(\"; rnf"n) -ns -o; } rtr 0 eun ; } / Cnrl tesaigfco / otos h pcn atr
Ba ck t o t op
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j k s c=1 ns=9 n , , , , , o ; fr( =1 c< 4 i+ { o i ; = ; +) / A w wn t pitteclmsi odsqec vz 135.t / s e at o rn h oun n d eune i. ,,,ec i (i%2 ! 0 { f ( ) = ) fr( =1 j< i j+ { pit(%c,pn) }fr( =ns s> 1 s- {/Tesaigfco o j ; = ; +) rnf"2" rt; o s o; = ; -) /h pcn atr i ( = 4& s= 1 { f c = & = ) bek ra; } pit( "; rnf" ) } fr( =1 k< i k+ { o k ; = ; +) i ( = 4& k= 5 { f c = & = ) bek ra; } pit(%c,pn) rnf"2" rt; } pit(\"; rnf"n) ns=ns-4 / cnrl tesaigfco o o ; / otos h pcn atr +c +; } } rtr 0 eun ; }
Ba ck t o t op
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
3/25
2/29/12
* * * * * * * *
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j k s p r ns=7 n , , , , , , o ; fr( =1 i< 5 i+ { o i ; = ; +) pit( rnf" } "; )
fr( =1 j< i j+ { i (i%2 ! 0& ( %2 ! 0 {pit(%c,pn) }es i (i%2 = 0& ( %2 = 0 {pit(%c,pn) } o j ; = ; +) f ( ) = & j ) = ) rnf"3" rt; le f ( ) = & j ) = ) rnf"3" rt;
fr( =1 k< i k+ {/Jiigsprt fgrsi ( = 5& k= 1 { cniu;}i (k%2 ! 0 {pit(%c,pn) }es {pit( o k ; = ; +) /onn eeae iue f i = & = ) otne f ( ) = ) rnf"3" rt; le rnf" pit( rnf" } fr( =1 k< p k+ { o k ; = ; +) i (k%2 ! 0 { f ( ) = ) pit(%c,pn) rnf"3" rt; } es { le pit( rnf" "; ) } } ns=ns+2 / saecnrl o o ; / pc oto pit(\"; rnf"n) } rtr 0 eun ; } "; )
fr( =1 r< p r+ {i (p%2 ! 0& ( %2 ! 0 {pit(%c,pn) }es i (p%2 = 0& ( %2 = 0 {pit(%c,pn) } o r ; = ; +) f ( ) = & r ) = ) rnf"3" rt; le f ( ) = & r ) = ) rnf"3" rt;
Explanation: This can be seen as an inverted diamond composed of stars. It can be noted that the composition of this figure follows sequential pattern of consecutive stars and spaces. In case of odd row number, the odd column positions will be filled up with *, else a space will be spaced and vice-versa in case of even numbered row. In order to achieve this we will construct four different right angle triangles aligned as per the requirement.
Ba ck t o t op
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j s ns=0 n , , , o ; fr( =9 i> 1 ( =i-2){ o i ; = ; i ) fr( =ns s> 1 s- { o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) i (i%2 ! 0& ( %2 ! 0 { f ( ) = & j ) = ) pit(%c,pn) rnf"2" rt; }es { le pit( "; rnf" ) } } pit(\"; rnf"n) ns+ o+; }
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
4/25
2/29/12
ns=3 o ;
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j k s ns=4 n , , , , o ; fr( =1 i< 5 i+ {fr( =ns s> 1 s- { o i ; = ; +) o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) pit(%c,pn) rnf"2" rt; } fr( =1 k< ( -1;k+ {i ( = 1 { o k ; = i ) +) f i = ) cniu;}pit(%c,pn) } pit(\"; otne rnf"2" rt; rnf"n) fr( =ns s> 1 s- { o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) pit(%c,pn) rnf"2" rt; } fr( =1 k< ( -1;k+ { o k ; = i ) +) pit(%c,pn) rnf"2" rt; } ns+ o+; pit(\"; rnf"n) } ns=3 o ; fr( =2 i< 5 i+ {i (i%2 ! 0 {fr( =ns s> 1 s- { o i ; = ; +) f ( ) = ) o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) pit(%c,pn) rnf"2" rt; } } i (i%2 ! 0 { f ( ) = ) pit(\"; rnf"n) nso-; }
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
5/25
2/29/12
} rtr 0 eun ; }
Program:
/ * Ti cnb se a torgtagetinlssaigtesm bs hs a e en s w ih nl rage hrn h ae ae wihi mdfe b adn fwetasitn sae hc s oiid y dig e xr hfig pcs * / #nld icue / Ti fnto cnrl teinrlo adtesaig / hs ucin otos h ne op n h pcn / fco gie b teotrlo idxadtesaigidx / atr udd y h ue op ne n h pcn ne. ittinl(n ns iti { n rageit o, n ) ca pn ='' hr rt *; its j n , ; fr( =ns s> 1 s- { o s o; = ; -) / Saigfco / pcn atr pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) /Teinrlo /h ne op pit(%c,pn) rnf"2" rt; } rtr 0 eun ; } itmi( { n an) iti ns=5 n , o ; /dasteuprtinl /rw h pe rage fr( =1 i< 4 i+ { tinl(o,i; o i ; = ; +) ragens ) itj=1 n ; tinl(o,i; / Inrlo cntuto ragens ) / ne op osrcin ns=ns-j o o ; / Saigfco / pcn atr pit(\"; rnf"n) } rtr 0 eun ; }
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j k s ns=-; n , , , , o 1 fr( =5 i> 1 i- { o i ; = ; -) fr( =1 j< i j+ { pit(%c,pn) }fr( =ns s> 1 s- { o j ; = ; +) rnf"2" rt; o s o; = ; -) pit( "; rnf" ) } fr( =1 k< i k+ { o k ; = ; +) i ( = 5& k= 5 { f i = & = ) cniu; otne
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
6/25
2/29/12
} pit(%c,pn) rnf"2" rt; } ns=ns+2 o o ; pit(\"; rnf"n) } ns=5 o ; fr( =2 i< 5 i+ { o i ; = ; +)
fr( =1 j< i j+ { pit(%c,pn) }fr( =ns s> 1 s- { o j ; = ; +) rnf"2" rt; o s o; = ; -) pit( "; rnf" ) } fr( =1 k< i k+ { o k ; = ; +) i ( = 5& k= 5 { f i = & = ) bek ra; } pit(%c,pn) rnf"2" rt; } ns=ns-2 o o ; pit(\"; rnf"n) } rtr 0 eun ; }
Program:
#nld icue itmi( { n an) ca pn ='' hr rt *; iti j k s s,ns=0 ns =-; n , , , , p o , op 1 fr( =9 i> 3 ( =i-2){ o i ; = ; i ) fr( =ns s> 1 s- { o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ {pit(%c,pn) }fr(p=ns;s > 1 s-){ o j ; = ; +) rnf"2" rt; o s op p = ; ppit( "; rnf" ) } fr( =1 k< i k+ { i ( = 9& k= 1 {cniu;}pit(%c,pn) }ns+ ns =ns +2 pit(\";}ns=4 fr( =9 i o k ; = ; +) f i = & = ) otne rnf"2" rt; o+; op op ; rnf"n) o ; o i ; fr( =ns s> 1 s- { o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) pit(%c,pn) rnf"2" rt; } ns+ o+; pit(\"; rnf"n) } rtr 0 eun ; }
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
7/25
2/29/12
******* ***** *** *
Program:
#nld icue / * *ns=Nm o sae rqie i tetinl. o u. f pcs eurd n h rage *i * * * / ittinl(n ns iti itsi){ n rageit o, n , n kp ca pn ='' hr rt *; its j n , ; fr( =ns s> 1 s- { o s o; = ; -) pit( "; rnf" ) } fr( =1 j< i j+ { o j ; = ; +) i (kp! 0 { f si = ) i ( = 4& j= 1 { f i = & = ) cniu; otne } } pit(%c,pn) rnf"2" rt; } rtr 0 eun ; } =Cutrfrtenm o cacest piti ec rw one o h u. f hrtr o rn n ah o si acaatri arw kp hrce n o. *si=Afa frcekn wehrt kp lg o hcig hte o
itmi( { n an) iti ns=4 n , o ; fr( =1 i< 7 ( =i+2){ o i ; = ; i ) tinl(o,i 0; ragens , ) nso-; pit(\"; rnf"n) } ns=5 o ; fr( =1 i< 4 i+ {tinl(,i 0;/oesaenee i ec cs o tefraintinl(o,i 1;/si pitn oesa i tels o i ; = ; +) rage1 , ) /n pc edd n ah ae f h omto ragens , ) /kp rnig n tr n h a tinl(,i 0; rage1 , ) tinl(o,i 0; ragens , ) ns=ns+2 o o ; pit(\"; rnf"n) } ns=1 o ; fr( =7 i> 1 ( =i-2){ o i ; = ; i ) tinl(o,i 0; ragens , ) ns+ o+; pit(\"; rnf"n) } rtr 0 eun ; }
Program:
#nld icue / * *ns=Nm o sae rqie i tetinl. o u. f pcs eurd n h rage *i =Cutrfrtenm o caatr t piti ec rw one o h u. f hrces o rn n ah o *si=Afa frcekwehrt kp lg o hc hte o * si acaatri arw kp hrce n o. * * /
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
8/25
2/29/12
About t he Aut hor: This post was written by Utsav Banerjee. You can reach Utsav on em ail at fugitiv eland@gm ail.com
Subscribe
Tagged as: pattern program s
Abiha_kazm i32
tel l m e th e code of fol l owi n g * *** **** ***** **** *** *
3 months ago 4 Li k es Li k e Repl y
Snehalv jadhav
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
9/25
2/29/12
tel l m e th e code of fol l owi n g pattern . * * * * * * * * *
4 months ago 5 Li k es
Li k e
Repl y
Mansi
#i n cl u de<stdi o.h > m ai n () { i n t i ,j,k,n ; pri n tf(h ow m an y l i n es y ou wan t to en ter:"); scan f("%d",&n ); for(i =1;i <=n ;i ++) { for(j=n ;j>=i ;j--) { pri n tf(" "); } for(k=1;k<=i -1;k++) { pri n tf("*"); pri n tf(" "); } pri n tf("\n "); } for(i =1;i <=n ;i ++) { for(j=1;j<=i -1;j++) { pri n tf(" "); } for(k=n ;k>=i ;k--) { pri n tf("*"); pri n tf(" "); } pri n tf("\n "); } }</stdi o.h >
4 months ago i n r epl y to Snehal v jadhav 6 Li k es Li k e Repl y
abc
gi v e m e th e code of fol l owi n g pattern * *** ***** *******
3 months ago 3 Li k es Li k e Repl y
Sarv esh445
v oi d m ai n () { i n t a,b; a=b=7/2+1;//n =n o of rows..n +(n -1)=7(for 4 rows) for(i n t i =1;i <=4;i ++) { for(i n t j=1;j<=7;j++) { i f(j>=a&&j<=b) pri n t("*"); } a--; b++; } }
2 months ago i n r epl y to ab c Li k e Repl y
v idhy a
can u tel l m e h ow to pu t ti s pattern * *** ***** *** *
8 months ago 7 Li k es Li k e Repl y
S.V.Ram ana
Th i s i s code for Lov en eesh 's ou tpu t l i ke ***** **** *** ** * #i n cl u de #i n cl u de
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
10/25
2/29/12
v oi d m ai n () { i n t i ,j,n ; cl rscr(); pri n tf("En ter n v al u e"); scan f("%d",&n ); for(i =n ;i >0;i --) { for(j=1;j<=i ;j++) { pri n tf("*"); } pri n tf("\n "); } getch (); }
5 months ago 4 Li k es
Li k e
Repl y
Hari
h ow can i pri n t '**'s fou r si des of screen ???? exam pl e l i ke th i s............ ************************************************************************ * * * * * * * *
Jay esh5101992sapkale
can U gi v e y ou r Em ai l i d I Wi l l Sen d u program sol u ti on b-coz con ten t n ot Fi t on i t,,,,,,,,,,,,,,,,If Y ou h av e A l ready Sol v ed th i s probl em th en V ery Good Try ...........
1 month ago i n r epl y to Har i Li k e Repl y
Jay esh5101992sapkale
i n t fi rst_term =1; v oi d m ai n () { i n t a[100][100]; i n t c=1,i =0,j=0,k=0,m =0,n =0,x=0; cl rscr(); pri n tf("En ter Rows an d col u m n s for th e squ are m atri x \n "); scan f("%d",&n ); x=n ; wh i l e(n >=1) { for(k=0;k<n ;k++) el se{a[k+m ][n -1+m ]="0;}" el se{a[m ][k+m ]="0;}" for(k="1;k&l t;n ;k++)" i f(fi rst_term ){a[k+m ][n -1+m ]="c++;}" i f(fi rst_term ){a[m ][k+m ]="c++;}">=0;k--) i f(fi rst_term ){a[n -1+m ][k+m ]=c++;} el se{a[n -1+m ][k+m ]=0;} for(k=n -2;k>0;k--) i f(fi rst_term ){a[k+m ][m ]=c++;} el se{a[k+m ][m ]=0;} i f(x==n ){ fi rst_term =0;} n -=2; m ++; } for(i =0;i <x;i ++) ");}="" ;}="" el se{pri n tf("="" for(j="0;j&l t;x;j++)" getch ();="" i f(a[i ][j]="=0) {pri n tf("" pri n tf("\n ");="" {="" }="" ="" *")=""></x;i ++)></n ;k++)>
1 month ago i n r epl y to Jay esh51 01 992sapk al e Li k e Repl y
Jay esh5101992sapkale
Rem ov e al l l ast l i n e from i t
1 month ago i n r epl y to Jay esh51 01 992sapk al e Li k e Repl y
Jay esh5101992sapkale
#i n cl u de <con i o.h > #i n cl u de <stdi o.h > i n t fi rst_term =1; v oi d m ai n () { i n t a[100][100];i n t c=1,i =0,j=0,k=0,m =0,n =0,x=0;cl rscr(); pri n tf("En ter th e n u m ber of rows an d col u m n s for th e squ are m atri x \n ");scan f("%d",&n );x=n ; </stdi o.h ></con i o.h >
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
11/25
2/29/12
1 month ago i n r epl y to Har i
Jay esh5101992sapkale
Hi Hari ,,,,,Ch eck th i s code i n c l an gu age..........i f an y Error Pl z Fi x i t.... Code: #i n cl u de <con i o.h >#i n cl u de <stdi o.h >i n t fi rst_term =1;v oi d m ai n (){i n t a[100][100];i n t c=1,i =0,j=0,k=0,m =0,n =0,x=0;cl rscr();pri n tf("En ter th e n u m ber of rows an d col u m n s for th e squ are m atri x \n ");scan f("%d",&n );x=n ;wh i l e(n >=1){for(k=0;k<n ;k++)i f(fi rst_term ){a[m ] [k+m ]=c++;}el se{a[m ][k+m ]=0;}for(k=1;k<n ;k++)i f(fi rst_term ){a[k+m ][n -1+m ]=c++;}el se{a[k+m ][n 1+m ]=0;}for(k=n -2;k>=0;k--)i f(fi rst_term ){a[n -1+m ][k+m ]=c++;}el se{a[n -1+m ][k+m ]=0;}for(k=n 2;k>0;k--)i f(fi rst_term ){a[k+m ][m ]=c++;}el se{a[k+m ][m ]=0;}i f(x==n ){fi rst_term =0;}n =2;m ++;}for(i =0;i <x;i ++){for(j=0;j<x;j++){ ");} ="" ;}}pri n tf("\n ");}getch ();}="" el se{pri n tf("="" i f(a[i ] [j]="=0){pri n tf("" ="" *")=""></x;i ++){for(j=0;j<x;j++){ ></n ;k++)i f(fi rst_term ){a[m ] [k+m ]=c++;}el se{a[m ][k+m ]=0;}for(k=1;k<n ;k++)i f(fi rst_term ){a[k+m ][n -1+m ]=c++;}el se{a[k+m ][n 1+m ]=0;}for(k=n -2;k></stdi o.h ></con i o.h >
1 month ago
i n r epl y to Har i
Li k e
Repl y
Jay esh5101992sapkale
sorry th i s i s n ot su i tabl e.,,,,I wi l l prov i de i n to parts
1 month ago i n r epl y to Jay esh51 01 992sapk al e Li k e Repl y
Sarv esh445
v oi d m ai n () { for(i n t i =1;i <=n ;i ++)//n i s an y i n teger v al u e for(i n t j=1;j<=n ;j++) i f(i ==1||i ==n ||j==1||j==n ) pri n t("*"); }
2 months ago i n r epl y to Har i Li k e Repl y
abc
gi v e m e th e code of fol l owi n g pattern 1 11 121 1331 14641
3 months ago 2 Li k es Li k e Repl y
Rohitarg91
great
4 months ago 2 Li k es Li k e Repl y
Rajsharm aj2ee
gi v e m e th e code of fol l owi n g ch aracter A B C D E F G F E D C B A A B CDE F F E DCB A A B CDE E DCB A A B CD A B C A B A pl s repl y si r code regards Raj v i sh wakarm a
2 months ago 1 Li k e Li k e Repl y
DC B A C B A B A A
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
12/25
2/29/12
pri n tf("%c",p-1); p--; } pri n tf("\n "); } getch (); } </con i o.h ></stdi o.h >
1 month ago
Li k e
Repl y
AT UBH BHAWARE
pl z som eon e tel l m e program for fol l owi n g ou tpu t ** **** ****** ******** ********** ******** ****** **** **
7 months ago 3 Li k es Li k e Repl y
Suhani6y adav
#i n cl u de<stdi o.h > m ai n () { i n t n , c, k, space = 1; pri n tf("En ter n u m ber of rows\n "); scan f("%d",&n ); space = n - 1; for ( k = 1 ; k <= n ; k++ ) { for ( c = 1 ; c <= space ; c++ ) pri n tf(" "); space--; for ( c = 1 ; c <= 2*k-1 ; c++) pri n tf("*"); pri n tf("\n "); } space = 1; for ( k = 1 ; k <= n - 1 ; k++ ) { for ( c = 1 ; c <= space; c++) pri n tf(" "); space++; for ( c = 1 ; c <= 2*(n -k)-1 ; c++ ) pri n tf("*"); pri n tf("\n "); } retu rn 0; }</stdi o.h >
2 months ago i n r epl y to A TU BH BHA W A RE Li k e Repl y
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
13/25
2/29/12
1 month ago
subbanaidu
#i n cl u de<stdi o.h > v oi d m ai n () {i n t i ,j,tem p=0; cl rscr(); for(i =0;i <n ;i ++) for(j="0;j&l t;n ;j++)" pri n tf("%d",tem p);="" tem p++;="" {="" }=""></n ;i ++)></stdi o.h >
3 months ago i n r epl y to supantha k umar pal Li k e Repl y
Dharm u1994
#i n cl u de<stdi o.h > m ai n () { i n t n , c, k,p=1; pri n tf("En ter n u m ber of rows\n "); scan f("%d",&n ); for ( c = 1 ; c <= n ; c++ ) { for( k = 1 ; k <= c ; k++ ) { pri n tf("%d",p); p=p+1; } pri n tf("\n "); } retu rn 0; }</stdi o.h >
4 months ago i n r epl y to supantha k umar pal Li k e Repl y
jasleen
can u pl ease gi v e m e a codi n g of th i s pattern ? * ** ** *******
6 months ago 2 Li k es Li k e Repl y
anony m ous
* * * * * * * * * n o. of rows to be en tered by u ser ?
3 months ago 1 Li k e Li k e Repl y
rashm i
pl z tel l m e codi n g ****** an d sen d m e code on m y em ai l -i d * * m y i d sm i l e_rash m i ch arjan @redi ff.com * * ******
4 months ago 1 Li k e Li k e Repl y
R.Mahalakshm i
i n eed si m pl e c program to pri n t l i ke a fol l owi n g pattern * *** ***** *** *
5 months ago 1 Li k e Li k e Repl y
Dineshrockzzz8
cl ass pattern 21st { pu bl i c stati c v oi d m ai n () { for(i n t i = 1 ; i <=5 ; i ++) { for(i n t j = 1 ; j <= i ; j++) { Sy stem .ou t.pri n t( "*" + " " ); } Sy stem .ou t.pri n tl n (); } for(i n t i = 4 ; i >=1 ; i --) { for(i n t j = 1 ; j <= i ; j++) { Sy stem .ou t.pri n t( "*" + " " ); } Sy stem .ou t.pri n tl n (); }
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
14/25
2/29/12
} }
1 month ago
1 Li k e
Li k e
Repl y
jy otish
pl z som eon e tel l m e program for fol l owi n g ou tpu t abcdedcba abcd dcba abc cba ab ab aa
6 months ago 1 Li k e Li k e Repl y
AT UBH BHAWARE
pl z som eon e tel l m e program for fol l owi n g ou tpu t * ** *** *****
7 months ago 1 Li k e Li k e Repl y
sai
to pri n t as *** ** *
7 months ago 1 Li k e Li k e Repl y
saurabh chopra
si r,How can we pri n t stars i n a ci rcl e?
7 months ago 1 Li k e Li k e Repl y
tejas chachad
h ey i wan t to pri n t ****** ** ** ** ******
1 0 months ago 1 Li k e Li k e Repl y
pratik
pl z h el p m i to wri te th s pattern program .. ***************** ** ** ****** ****** 1** ** **** **** ** ***********
1 1 months ago 1 Li k e Li k e Repl y
Pram od
* ** ** ******
1 y ear ago 1 Li k e Li k e Repl y
m athapelo
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
15/25
2/29/12
Utsav Banerjee
A s th e au th or of th e post , I wou l d l i ke to requ est ev ery on e n ot to ask for ready m ade codes as I am stri ctl y agai n st spoon feedi n g. Pl ease try ou t th e probl em y ou rsel f post y ou r code i n pastebi n .com n refer u s th e l i n k so th at we can v eri fy y ou r code, an d h el p y ou sol v e th e ri ddl e. Th an ki n g Y ou Utsav Ban erjee
1 y ear ago 1 Li k e Li k e Repl y
Sahil
tel l m e th e code of th i s 1 23 456 7 8 9 10
1 y ear ago 1 Li k e Li k e Repl y
sridhar
Th e credi t of th i s post goes to Utsav Ban erjee.. Good work Utsav ! Edi tor, In terv i ew Man tra
2 y ear s ago 1 Li k e Li k e Repl y
Haem obindium
pl ease tel l m e th e c code for th e fol l owi n g pattern ***** **** *** ** *
5 day s ago Li k e Repl y
Aarthi
wan t i n jav a program m i n g...
1 w eek ago Li k e Repl y
Ridzi0207
pl z tel l m e th e code for ******* ******* *** * *** *******
1 month ago Li k e Repl y
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
16/25
2/29/12
i n t i ,j,k,l ,m ,n ,o;{ for(i =0;i <=1;i ++){pri n tf("\n ");
for(j=0;j<=6;j++) pri n tf("*");}for(k=0;k<=1;k++){pri n tf("\n ");for(l =0;l <=1+k;l ++)pri n tf(" ");for(m =0;m <=22*k;m ++)pri n tf("*");}pri n tf("\n ***\n ");for(o=0;o<=6;o++){pri n tf("*");}}getch ();}</con i o.h > </stdi o.h >
5 day s ago i n r epl y to Ri dzi 0207 Li k e Repl y
Nkkoolguy
* **
Ajay
pl ease gi v m e th e code for fol l owi n g pattern ! 1 11 21 1211 111221 312211 13112221
2 months ago Li k e Repl y
Grissar
Wou l d som eon e be abl e to h el p wi th creati n g a h ol l ow tri an gl e i n Jav a l ooki n g l i ke th i s: ----*-------*-*-----*---*---*-----*-********* Wh ere th e - equ al s a space. A u ser en ters a n u m ber an d th e tri an gl e h ei gh t = th e n u m ber. I h av e th i s code so far bu t I can 't get an y fu rth er. N ot ev en su re i f I'm on th e ri gh t track an y m ore: h ttp://pastebi n .com /rUrKaV W5 Th an ks i n adv an ce.
2 months ago Li k e Repl y
Grissar
Th e drawi n g di dn 't com e ou t ok. So, h ere's a ph oto.
2 months ago i n r epl y to Gr i ssar Li k e Repl y
deepak singla
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
17/25
2/29/12
gi v e m e th e code of fol l owi n g pattern 1 01 101 0101 10101
2 months ago
Li k e
Repl y
Bschinku
th an x dear
3 months ago Li k e Repl y
Sudhir
pl ease can y ou prov i de th e code for fol l owi n g pattern i n C++ H L H E H EEEEE L L OOOOH O OHHHHH EEEEE L L L O OH H L H E O EEEEE L OH LLLLL L H O E L OOOOO OH H L E O L OH
LLLLL
Dsasd
#i n cl u de<stdi o.h > v oi d m ai n () { pri n tf("H H E pri n tf(" L H EEEEE L O OHHHHH L L EEEEE O OOOOH L OH L H H E O EEEEE L OH LLLLL L H E O L OOOOO\n "); OH
L \n ");
LLLLL
Li k e
Repl y
siv a
so di ff to get!!!
4 months ago Li k e Repl y
Manish Prajapati1991
pl ease gi v e m e h el p for pri n ti n g bel ow pattern . i f i n pu tn i s 5 th en 1 2 3 4 516 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
4 months ago Li k e Repl y
KALE SOMNAH
PLS tel l m e code to weth er th e gi v en stri g s pal i oderm or n ot
5 months ago Li k e Repl y
Bujji
Aim : to fi n d wh eth er gi v en stri n g i s pal i n drom e or n ot In pu t : accept a stri n g Ou tpu t : pal i n drom e or n ot Program : #i n cl u de<stdi o.h > i n t m ai n (v oi d) { ch ar st[20],rev [20]; i n t l =0,i ; cl rscr(); pri n tf("en ter a stri n g"); scan f("%s",&st); for(;st[l ]!='\0';l ++); fi n d l en gth of a stri n g*/ for(i =0;i <l ;i ++) &="" *to="" 2="" ;="" a="" break="" break; ="" bu n n y ="" com pare="" /*to
el se="" en ter="" for(i ="0;i &l t;l ;i ++)" i f(i ="=l ) " i f(st[i ]!="rev [i ]) " i n pu t ="" l en gth s="" l oop*="" m adam ="" n ot="" of="" ori gi n al ="" ou tpu t:="" pal i n drom e="" pal i n drom e");="" pri n tf("n ot="" pri n tf("pal i n drom e");="" rev [i ]="st[l -i -1]; stri n g*="" th e="" {="" }="" ="" ="" =""
3 months ago i n r epl y to KA LE SOMN A H
" rev [l ]="\0" rev erse="" rev ersed="" sri n gs*="" stri n g="" =""></l ;i ++)></stdi o.h >
Li k e Repl y
1 Li k e
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
18/25
2/29/12
Mallickanurag25
#i n cl u de<stdi o.h > v oi d m ai n () { i n t r=0,x,y ,z;
pri n tf("En ter th e n u m ber to be ch ecked "); scan f("%d",&x); y =x; wh i l e (x!=0) { r=(r*10)+(x%10); x=x/10; z=r; } i f (y ==z) { pri n tf("th e gi v en n u m ber i s a pal l i n drom e."); } el se { pri n tf("th e gi v en n u m ber i s n ot a pal l i n drom e."); } }</stdi o.h >
5 months ago i n r epl y to KA LE SOMN A H Li k e Repl y
ankur lov ed
th i s i s n ot th e opti m i zed code th i s wi l l u se m ore m em ory
5 months ago Li k e Repl y
lov eneesh
m i rror i m age of th i s ***** **** *** ** *
5 months ago Li k e Repl y
Dineshrockzzz8
cl ass pattern 1st { pu bl i c stati c v oi d m ai n () { for(i n t i = 1 ; i <=5 ; i ++) { for(i n t j = 1 ; j <= i ; j++) { Sy stem .ou t.pri n t( "*" + " " ); } Sy stem .ou t.pri n tl n (); } } }
1 month ago i n r epl y to l ov eneesh Li k e Repl y
Dharm u1994
#i n cl u de<stdi o.h > v oi d m ai n () { i n t n , c, k; pri n tf("En ter n u m ber of rows\n "); scan f("%d",&n ); for ( c = 1 ; c <= n ; c++ ) { for( k = c ; k <= n ; k++ ) pri n tf("*"); pri n tf("\n "); }
lov eneesh
***** **** *** ** *
5 months ago Li k e Repl y
Angad tom ar
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
19/25
2/29/12
for(i =n ;i >0;i --) { pri n tf(" "); for(j=1;j<=i ;j++) { pri n tf("*"); } pri n tf("\n "); }
1 month ago
i n r epl y to l ov eneesh
Li k e
Repl y
lov eneesh
h ow can i pri n t th e pattern ***** **** *** ** *
5 months ago Li k e Repl y
Vjy
1 141 13531 1357531 13531 141 1
5 months ago Li k e Repl y
jev ie m ar galaura
i h av e probl em i n m y codes pl ease sen t m e an d em ai l on asteri sk pattern s pl ease!!!!!!!!
5 months ago Li k e Repl y
sushant choudhary
code to pri n t th e fol l owi n g pattern : 1 131 13531 1357531 13531 131 1
5 months ago Li k e Repl y
jasleen
abov e i s n ot exact pattern m ay b som e probl em i n pri n ti n g th e pattern i s : th ere i s th ree spaces an d th en star i n fi rst l i n e i n secon d l i n e two spaces th en star th en on e space an d agai n star i n th i rd l i n e on e space on e star th en th ree spaces on e star i n fou rth l i n e sev en stars.
6 months ago Li k e Repl y
jasleen
can u pl ease gi v e m e a codi n g of th i s pattern ? *
6 months ago Li k e Repl y
Rajitha
1111111 1221 1331 141 1331 1221 1111111 can an y on e do th i s?????????
6 months ago Li k e Repl y
saurabh
h el oo fri en ds y ou r m i n d i s v ery sh arp becou se y ou r program i n g i s v ery di l i ci ou s
6 months ago Li k e Repl y
am it sisodiaa
th i s i s so goood for begai n er
6 months ago Li k e Repl y
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
20/25
2/29/12
ajit sujit
accesscode
***** **** *** ** * Try th i s>>>>>
6 months ago Li k e Repl y
Him karjha2042
#i n cl u de<stdi o.h > #i n cl u de<con i o.h > v oi d m ai n () { i n t i ,j,; cl rscr(); for(i =6;i >0;i --) { for(j=1;j<=i ;j++) { pri n tf("*"); } pri n tf("\n "); } getch (); }</con i o.h ></stdi o.h >
4 months ago i n r epl y to ac c essc ode 1 Li k e Li k e Repl y
jadoo
#i n cl u de #i n cl u de #i n cl u de #i n cl u de #i n cl u de #i n cl u de #i n cl u de u si n g n am espace std; i n t m ai n () { for(i n t i =1;i <=5;i ++) { for(i n t j=1;j<=i ;j++) { cou t<<"**"; } cou t<=1;i --) { for(i n t j=i ;j>=1;j--) { cou t<<"**"; } cou t<<en dl ; } retu rn 0; }
6 months ago Li k e Repl y
nitesh
th i s i s th e best for bi gn ers
6 months ago Li k e Repl y
Ashu
th an ks . th i s i s v ery h el pfu l
7 months ago Li k e Repl y
Mahendra
Hey Su sh an t Ur Code i s Here n ow ,.....Mah en dra(May u r) #i n cl u de #i n cl u de v oi d m ai n () { i n t i ,j,n ; cl rscr(); pri n tf(\n En ter th e n u m ber :); scan f(%d,&n ); for(i =n ;i >0;i ) { for(j=i ;j<=n ;j++) {
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
21/25
2/29/12
pri n tf("*"); } pri n tf("\n "); } for(i =0;i <=n ;i ++) { for(j=i ;j<n -1;j++) { pri n tf("*"); } pri n tf("\n "); } getch (); } /* En ter th e n u m ber :5 * ** *** **** ***** **** *** ** * */
7 months ago
Li k e
Repl y
Am an
code for th e patern : 1 26 3 7 10 4 8 11 13 5 9 12 14 15 h ere i t goes: #i n cl u de #i n cl u de v oi d m ai n () { i n t i ,j,a,n ; cl rscr(); pri n tf("\n En ter th e n o. of l i n es to be pri n ted."); scan f("%d",&n ); for(i =1;i <=n ;i ++) { pri n tf("\n "); a=i ; for(j=1;j<=i ;j++) { pri n tf("%d ",a); a=a+n -j; } } getch (); } En joy bu di es...;)
8 months ago Li k e Repl y
Nikhil
***** ** ** ****
8 months ago Li k e Repl y
rishav
sry dere was probl m i s pasti n g d code,,,,,,,,di s i s ry t code V IDHY A #i n cl u de i n t m ai n () { i n t k,m ,n ,i ,j,l ; pri n tf("en ter th e si ze of th e prog:"); scan f("%d",&n ); m =n ; for(j=1;j<=n ;j++) { i f((j<=n /2+1)) { k=j*2-1; for(l =1;l n /2+1) { k=m -2; m =k; for(i =1;i <=k;i ++) { pri n tf("*"); } pri n tf("\n "); } el se
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
22/25
2/29/12
{ con ti n u e; }} retu rn 0; }
8 months ago
Li k e
Repl y
rishav
di s i s u r code ,,,,,,,,,,,,V IDHY A #i n cl u de i n t m ai n () { i n t k,m ,n ,i ,j,l ; pri n tf("en ter th e si ze of th e prog:"); scan f("%d",&n ); m =n ; for(j=1;j<=n ;j++) { i f((j<=n /2+1)) { k=j*2-1; for(l =1;l n /2+1) { k=m -2; m =k; for(i =1;i <=k;i ++) { pri n tf("*"); } pri n tf("\n "); } el se { con ti n u e; }} retu rn 0; }
8 months ago Li k e Repl y
preethi
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
23/25
2/29/12
tel l m e th e code for a aa aaa aaaa aaaaa
8 months ago
Li k e
Repl y
rishav
h ere i s y ou r code ,,,,,,,,, sh ah n awaz #i n cl u de i n t m ai n () { i n t m ,i ,j,k,p; pri n tf("en ter th e si ze of th e program "); scan f("%d",&m ); k=p=m ; for(i =0;i <m ;i ++) { for(j=0;j<m ;j++) { i f(i <=j) { pri n tf("%d",p); p--; }} p=k; pri n tf("\n "); } retu rn 0; }
8 months ago Li k e Repl y
rishav
#i n cl u de i n t m ai n () { i n t m ,n ,i ,j; m =6; n =11; for(i =0;i <6;i ++) { for(j=0;j<11;j++) { i f(i <5&&j<2) pri n tf("*"); el se i f(i ==5) pri n tf("*"); el se con ti n u e; } pri n tf("\n "); } retu rn 0; } h ere i s code for pri n ti n g........... ** ** ** ** ** ***********
8 months ago Li k e Repl y
rishav
#i n cl u de i n t m ai n () { i n t m ,i ,j; pri n tf("en ter th e si ze of program \n "); scan f("%d",&m ); for(i =0;i <m ;i ++) { for(j=0;j<m ;j++) { i f(i <=j) pri n tf("*"); } pri n tf("\n "); } retu rn 0;}
8 months ago Li k e Repl y
m anali
pl z tel l m e h ow to pri n t th e fol l owi n g pattern ? ****** ***** **** *** ** *
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
24/25
2/29/12
8 months ago
shahnawaz
pl z h el p m e to wri te th i s program 54321 5432 543 54 5
8 months ago Li k e Repl y
Saptapratim Bose
for(j=1;j<=5;j++) { for(i =5;i ,=j;i --) pri n tf('i "); pri n tf("\n "0; } Repl y saptaprati m Bose
3 months ago i n r epl y to shahnaw az Li k e Repl y
Saptapratim Bose
for(j=1;j<=5;j++) { for(i =5;i ,=j;i --) pri n tf('i "); pri n tf("\n "); } Repl y saptaprati m Bose
3 months ago i n r epl y to Saptapr ati m Bose Li k e Repl y
jy othi
** ** * ** **
9 months ago Li k e Repl y
M Su bscri be by em ai l
S RSS
Loa d m or e c om m en t s
Trackback URL h ttp://www.i n terv i ewm an tra.n et/2009/10/10-star-pattern -program s.h tm l /trackback
P R E V I OU S P OS T: N E X T P OS T:
www.interviewmantra.net/2009/10/10-star-pattern-programs.html
25/25