2/29/12
10 Challenging star pattern programs in C | Interview Mantra
10 Challenging Challenging star pattern p attern programs pr ograms in C by U T S A V B A N E R J E E on O C T O B E R 1 9 , 2 0 0 9
Samsung Mobile Phones Discover Samsung phones today. All Phones range. Official Site. Visit! www.Samsung.com
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, understandin understanding g the proble m, writing an algorithm, writing a program and most importantly runnin running g the pro gram and obtaining required output. Here are few challenging C program questions for you. Let’s 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.
Also read Number Pattern Programs 1. Write a C program to print the following pattern:
* *
*
* * * *
* * *
2. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3. Write a C program to print the following pattern: *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
*
*
* *
*
*
* *
*
*
4. Write a C program to print the following pattern: *
* *
* *
*
* *
* *
* *
* *
* * * * *
* *
* *
* *
*
* *
*
5. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * *
2/29/12
10 Challenging star pattern programs in C | Interview Mantra * * * * * * * * * * * * * * * * *
6. Write a C program to print the following pattern: * * * * * * * * * * * * * * * *
7. Write a C program to print the following pattern: * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* * * * * * * * *
8. Write a C program to print the following pattern: * * * * * * * * * *
* * * * *
* * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * *
* * * *
* * * * *
* * * * * * * * * * * * * * * * * * * * * *
10. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2/29/12
10 Challenging star pattern programs in C | Interview Mantra 1. Write a C program to print the following pattern:
*
* *
* * *
* * * *
Program:
/* This is a simple mirror-image of a right angle triangle */ #include int main() { char prnt = '*'; int i, j, nos = 4, s; for (i = 1; i <= 5; i++) { for (s = nos; nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", printf("%2c" , prnt); } printf("\n"); --nos; // Controls the spacing factor } return 0;
// Spacing facto
}
Download Code
Back to top
2. Write C program to print print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program:
#include int main() { char prnt = '*'; int i, j, k, s, c = 1, nos = 9; for (i = 1; c <= 4; i++) { // As we want to print the columns in odd sequence viz. 1,3,5,.etc if ((i % 2) != 0) { for (j = 1; j <= i; j++) { printf("%2c" printf("%2c", , prnt); } for (s = nos; s >= if (c == 4 && s == 1) { break; } printf("
"); } for (k = 1; k <= i; k++) { if (c == 4 && k == 5) { break; } printf("%2c", printf("%2c ", prnt); } printf("\n"); nos = nos - 4; ++c;
// controls the spacing factor
} } return 0; }
Download Code
Back to top
3. Write C program to print print the following pattern: *
* *
*
* *
* *
* *
*
* *
* *
*
*
2/29/12
10 Challenging star pattern programs in C | Interview Mantra *
*
*
*
* *
*
*
Program:
#include int main() { char prnt = '*'; int i, j, k, s, p, r, nos = 7; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) { printf(" ");
if ((i % 2) != 0 && (j % 2) != 0) { printf(" printf("
} for (k = 1; k <= i; k++) { //Joining seperate seperate figures if (i == 5 && k = for (r = 1; r <= p; r++) { if ((p % 2) != 0 && (r % 2) != 0) { printf(" printf(" "); } for (k = 1; k <= p; k++) { if ((k % 2) != 0) { printf("%3c", printf("%3c ", prnt); } else { printf(" "); } } nos = nos + 2; // space control printf("\n"); } return 0; }
Download Code
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 co lumn 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. Back to top
4. Write a C program to print the following pattern: *
* *
* *
*
* *
* *
* *
* *
* * * * *
* *
* *
* *
*
* *
*
Program:
#include int main() { char prnt = '*'; int i, j, s, nos = 0; for (i = 9; i >= 1; (i = i - 2)) { for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { if ((i % 2) != 0 && (j % 2) != 0) { printf("%2c", printf("%2c ", prnt); } else { printf(" "); } } printf("\n");
2/29/12
10 Challenging star pattern programs in C | Interview Mantra nos = 3; for (i = 3; i <= 9; (i = i + 2)) { for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { if ((i % 2) != 0 && (j % 2) != 0) { printf("%2c", printf("%2c ", prnt); } else { printf(" "); } } nos--; printf("\n"); } return 0; }
Download Code Back to top
5. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * *
* * * *
* * * * * * * *
* * * * * * * * * * * * * * * * *
Program:
#include int main() { char prnt = '*'; int i, j, k, s, nos = 4; for (i = 1; i <= 5; i++) { for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", printf("%2c" , prnt); } for (k (k = 1; k <= (i (i - 1); k++) { if (i == 1) 1) { continue; } printf(" printf(" for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", printf("%2c" , prnt); } for (k = 1; k <= (i - 1); k++) { printf("%2c", printf("%2c" , prnt); } nos++; printf("\n"); } nos = 3; for (i = 2; i <= 5; i++) { if ((i % 2) != 0) { for (s = nos; s >= 1; s--) printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", printf("%2c ", prnt); } } if ((i % 2) != 0) { printf("\n"); nos--;
2/29/12
10 Challenging star pattern programs in C | Interview Mantra } return 0; }
Download Code Back to top
6. Write a C program to print the following pattern: * * * * * * * * * * * * * * * *
Program:
/* This can be seen as two right angle triangles sharing the same base which is modified by adding few extra shifting spaces */ #include // This function controls the inner loop and the spacing // factor guided by the outer loop index and the spacing index. int triangle(int nos, int i) { char prnt = '*'; int s, j; for (s = nos; s >= 1; s--) { // Spacing factor printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", prnt); } return 0;
//The inner loop
} int main() { int i, nos = 5; //draws the upper triangle for (i = 1; i <= 4; i++) { triangle(nos triangle(nos, , i); int j = 1; triangle(nos, i); // Inner loop construction construction nos = nos - j; // Spacing factor
//Inner loop constructio
printf("\n"); } return 0; }
Download Code Back to top
7. Write a C program to print the following pattern: * * * *
* * * * * * * * * * * * * * * * * * *
* * * *
* * * * *
* * * * * * * * * * * * * * *
* * * * *
* * * *
Program:
#include int main() { char prnt = '*'; int i, j, k, s, nos = -1; for (i = 5; i >= 1; i--) { for (j = 1; j <= i; j++) { printf(" "); } for (k = 1; k <= i; k++) { if (i == 5 && k == 5) {
printf("%2c", prnt); prnt); } for (s = nos; s >= 1;
2/29/12
10 Challenging star pattern programs in C | Interview Mantra } printf("%2c", printf("%2c" , prnt); } nos = nos + 2; printf("\n"); } nos = 5; for (i = 2; i <= 5; i++) { for (j = 1; j <= i; j++) { printf(" "); } for (k = 1; k <= i; k++) { if (i == 5 && k == 5) { break; } printf("%2c", printf("%2c" , prnt); }
printf("%2c", prnt); prnt); } for (s = nos; s >= 1;
nos = nos - 2; printf("\n"); } return 0; }
Download Code Back to top
8. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program:
#include int main() { char prnt = '*'; int i, j, k, s, sp, nos = 0, nosp = -1; for (i = 9; i >= 3; (i = i - 2)) { for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { printf("%2c" printf("%2c", , prnt); } for (sp = nosp; sp >= printf(" "); } for (k = 1; k <= i; k++) { if (i == 9 && k == 1) { continue; continue; } printf(" for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { printf("%2c", printf("%2c" , prnt); } nos++; printf("\n"); } return 0; }
Download Code Back to top
9. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* * * * * * * * * * * * * * * * *
2/29/12
10 Challenging star pattern programs in C | Interview Mantra * * * * * * * * * * * * * * * *
Program:
#include /* * nos = * i = * skip= * *
Num. of spaces required in the triangle. Counter for the num. num. of charcters charcters to print in each row A flag for checking whether to skip a character in a row.
*/ int triangle(int nos, int i, int skip) { char prnt = '*'; int s, j; for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { if (skip != 0) { if (i == 4 && j == 1) { continue; } } printf("%2c", prnt); } return 0; } int main() { int i, nos = 4; for (i = 1; i <= 7; (i = i + 2)) { triangle(nos, i, 0); nos--; printf("\n"); } nos = 5; for (i = 1; i <= 4; i++) { triangle(1, i, 0); //one space needed in each triangle(1, i, 0); triangle(nos, i, 0); nos = nos + 2; printf("\n"); } nos = 1; for (i = 7; i >= 1; (i = i - 2)) { triangle(nos, i, 0); nos++; printf("\n"); } return 0; }
Download Code Back to top
10. Write a C program to print the following pattern: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
*
* * *
*
*
* *
* *
*
* *
*
* *
*
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program:
#include /* * nos = Num. of spaces required in the triangle. * i = Counter for the num. num. of characters characters to to print in in each row row * skip= A flag for check whether to * skip a character in a row. *
2/29/12
10 Challenging star pattern programs in C | Interview Mantra int triangle(int nos, int i, int skip) { char prnt = '*'; int s, j; for (s = nos; s >= 1; s--) { printf(" "); } for (j = 1; j <= i; j++) { if (skip != 0) { triangle(nos, i, 0); triangle(nosp, triangle(nosp , i, 1); triangle(nbsp, triangle(nbsp , i, 1); printf("\n"); nos++; nosp = nosp + 2; nbsp = nbsp + 2; } nos = 3, nosp = 5, nbsp = 5;
if (i == 9 && j == 1) {
for (i = 3; i <= 9; (i = i + 2)) { triangle(nos, i, 0); triangle(nosp, triangle(nosp , i, 1); triangle(nbsp, triangle(nbsp , i, 1); printf("\n"); nos--; nosp = nosp - 2; nbsp = nbsp - 2; } return 0; }
Download Code Back to top
Over 1600 professionals follow Interview Mantra. Enter your email address
Send email updates
About Abo ut t he Auth or: This post post was written by Utsav Banerjee. You can r each Utsav on email at
[email protected]
2,394 readers have already subscribed to email up dates! Enter your email address:
Subscribe Tagged as: pattern programs
Like
Add New Comment
Showing 100 of 128 comments
Abiha_kazmi32 tell m e the code of following * *** **** ***** **** *** *
Snehalvjadhav
Login
Sort by popular now
2/29/12
10 Challenging star pattern programs in C | Interview Mantra tell me the code of of following pattern . * * * * * * * * *
Mansi #include
main() { int i ,j, ,j,k,n; k,n; printf(how many lines you want to enter:"); enter:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=n;j>=i;j--) { printf(" "); } for(k=1;k<=i-1;k++) { printf("*"); printf(" "); } printf("\n"); } for(i=1;i<=n;i++) { for(j=1;j<=i-1;j++) { printf(" "); } for(k=n;k>=i;k--) { printf("*"); printf(" "); } printf("\n"); } }
abc giv e me the code of of following pattern * *** ***** *******
Sarvesh445 v oid oid m ain() { int a,b; a=b=7/2+1;//n=no a=b=7/2+ 1;//n=no of rows..n+(n-1)=7(for 4 rows) for(int i=1;i<=4;i++) { for(in t j=1;j<=7;j++) j=1;j<=7;j++) { if(j>=a&&j<=b) print("*"); } a--; b++; } }
vidhya can u tell me how to put put tis pattern * *** ***** *** *
S.V.Ramana This is code for Loveneesh's Loveneesh's output l ike ***** **** *** ** * #include
2/29/12
10 Challenging star pattern programs in C | Interview Mantra void vo id mai n() { int i,j,n; clrscr(); printf("Enter printf(" Enter n value"); scanf("%d",&n); for(i=n;i>0;i--) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } getch(); }
Hari how can i print '**'s four sides of screen???? example like this............ ************************************************************************ *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
************************************************************************* can an y 1 help me??????please....... me??????please.......
Jayesh5101992sapkale can U giv e your Email i d I Will Will Send u program soluti on b-coz content not Fit on on it,,,,,,,,,,,,,,,,If it,,,,,,,,,,,,,,,,If You hav e Already Solved thi s problem then V ery Good Good Try........... Try...........
Jayesh5101992sapkale int first_te first_term=1; rm=1; void vo id mai n() { int a[100][100 a[100][100]; ]; int c=1,i=0,j=0,k=0,m=0,n=0,x=0; clrscr(); printf("Enter Rows and columns for the square matrix \n"); scanf("%d",&n); x=n; while(n>=1) { for(k=0;k
if(first_term){a[m][k+m]="c++;}">=0;k--)
if(first_term){a[n-1+m][k+m]=c++;} else{a[n-1+m][k+m]=0;} for(k=n-2;k>0;k--) if(first_term){a[k+m][m]=c++;} else{a[k+m][m]=0;} if(x==n){ first_term=0;} n-=2; m++; } for(i=0;i
< "> )>
Jayesh5101992sapkale Remove all last line from it
Jayesh5101992sapkale
#inclu de
#inclu de int first_term=1; v oid oid m ain() { int a[100][100];int c=1,i=0,j=0,k=0,m=0,n=0,x=0;clrscr();
2/29/12
10 Challenging star pattern programs in C | Interview Mantra
Jayesh5101992sapkale Hi Hari ,,,,,Check ,,,,,Check thi s code in c la ngu age..........if any Error Plz Fix it.... Code: #inclu de # #incl incl ude int first_term=1;void main (){int a[100][100]; a[100][100];int int c=1,i=0,j=0 c=1,i=0 ,j=0,k=0, ,k=0,m=0,n=0 m=0,n=0,x=0; ,x=0;clrscr();printf clrscr();printf ("Enter the nu mber of rows a nd colum ns f or the square matri x \n");scanf("%d", \n");scanf("%d",&n);x=n;while(n>=1){ &n);x=n;while(n>=1){for(k=0 for(k=0;k=0;k--)if(first_term){a[n-1+m][k+m]=c++;}else{a[n-1+m][k+m]=0;}for(k=n2;k>0;k-2;k> 0;k--)if(fir )if(fir st_term){a[k+m][m]=c+ st_term){a[k+m][m]=c++; +;}else{a[k+ }else{a[k+m][m]=0;} m][m]=0;}if(x==n){first_term=0; if(x==n){first_term=0;}n}n=2;m++;}for(i=0;i< ">
Jayesh5101992sapkale sorry this is not suitable.,,,,I will provide in to parts
Sarvesh445 v oid oid m ain() { for(int i=1;i<=n;i++)//n is any integer value for(in t j=1;j<=n;j++) j=1;j<=n;j++) if(i==1||i==n||j==1||j==n) print("*"); }
abc giv e me the code of of following pattern 1 11 121 1331 14641
Rohitarg91 great
Rajsharmaj2ee giv e me the code code of following chara cter A B C D E F G F E D C B A A B CD EF
F E D C B A
A B CDE
E D C B A
A B CD
D C B A
A B C
C B A
A B
B A
A
A
pls reply sir code regards Raj vishwakarma
Bindu Kamboj #include #include v oid oid m ain() int i ,j,k,l,a=1,d= ,j,k,l,a=1,d=2,x; 2,x; char p='A'; A '; for(i=1;i<=6-1;i++) { for(j=1;j<=7-i;j++) { printf("%c",p); p++; } x=a+(i-1)*d; for(k=1;k<=x;k++) { printf (" "); "); } for(l=1;l<=7-i;l++)
2/29/12
10 Challenging star pattern programs in C | Interview Mantra printf("%c",p-1); p--; } printf("\n"); } getch(); }
AT UBH BHAWARE BHAWARE plz someone tell me program for following output ** **** ****** ******** ********** ******** ****** **** **
Suhani6yadav #include main() { int n , c, k, space = 1; printf("Enter nu mber of rows\n"); scanf("%d",&n); space = n - 1; for ( k = 1 ; k <= n ; k++ ) { for ( c = 1 ; c <= space ; c++ ) printf(" "); space--; for ( c = 1 ; c <= 2*k-1 ; c++) printf("*"); printf("\n"); } space = 1; for ( k = 1 ; k <= n - 1 ; k ++ ) { for ( c = 1 ; c <= space; c++) printf(" "); space++; for ( c = 1 ; c <= 2*(n-k)-1 ; c++ ) printf("*"); printf("\n"); } return 0; }
supantha kumar pal plz tell the code.... 1 23 456 7 8 9 10
Bindu Kamboj #include v oid oid m ain() { int i,j,a=1; for(i=1;i<=4;i++) { for(j=1;j { printf("%d",a); a++; } printf("\n"); } getch();
2/29/12
10 Challenging star pattern programs in C | Interview Mantra
subbanaidu #include v oid oid m ain() {int i ,j,temp=0 ,j,temp=0;; clrscr(); for(i=0;i }="">
Dharmu1994 #include main() { int n , c, k,p=1; k,p=1; printf("Enter nu mber of rows\n"); scanf("%d",&n); for ( c = 1 ; c <= n ; c++ ) { for( k = 1 ; k <= c ; k++ ) { printf("%d",p); p=p+1; } printf("\n"); } return 0; }
jasleen can u please give me a coding of this pattern? * ** ** *******
anonymous *
*
* * * * * *
*
no. of rows to be entered entered by u ser ?
rashmi plz tell me coding ****** an d send me code code on on my em ail -id *
* my id [email protected] [email protected] m
*
*
******
R.Mahalakshmi i need simple c pro program gram to print like a follo following wing patter pattern n * *** ***** *** *
Dineshrockzzz8 class pattern21st { public static void main () { for(i nt i = 1 ; i <=5 ; i++) { for(in t j = 1 ; j <= i ; j++) { System.out.prin t( "*" + " " ); } System.out.println(); } for(int i = 4 ; i >=1 ; i--) { for(in t j = 1 ; j <= i ; j++) { System.out.prin t( "*" + " " ); }
2/29/12
10 Challenging star pattern programs in C | Interview Mantra } }
jyotish plz someone tell me program for following output abcdedcba abcd dcba abc cba ab ab aa
AT UBH BHAWARE BHAWARE plz someone tell me program for following output * ** *** *****
sai to print as *** ** *
saurabh saurab h chopra sir,How sir,Ho w can we print stars i n a circle?
tejas chachad hey i want to print ****** ** ** ** ******
ankita srivastava #include#include int main() {
int i,j,k,l; for(j=0;j<=5;j++) printf("*"); for(i=0;i<=2;i++)
{
printf("\n\n"); for(k=0;k<=1;k++) printf ("* "); "); } printf("\n\n"); for(l=0;l<=5;l++) printf("*");
getch();
}
pratik plz help mi to write ths pattern program.. program.. ***************** ** ** ****** ****** 1** ** **** **** ** ***********
Pramod * ** ** ******
2/29/12
10 Challenging star pattern programs in C | Interview Mantra 8 Write a separate algorith m for a program to output output each of the followin g patterns [Note: There There are four tria ngl es of stars labell ed (a) (b) (c) (d). Each Each tri ang le consists of ten lin es of stars. Starting from lin e 1 to 10, the the num ber of of stars either increases by 1 from 1 to 10 or decreases by 1 from 10 to 1]: (a) (b) (c) (d) * ********** ********** * ** ********* ********* ** *** ******** ******** *** **** ******* ******* **** ***** ****** ****** ***** ****** ***** ***** ****** ******* **** **** ******* ******** *** *** ******** ********* ** ** ********* ********** * * **********
Utsav Banerjee As the au thor of the post post , I would like to request request everyone not to ask for ready ma de codes codes as I am stri ctly agai nst spoon feeding feeding . Please try out the problem yourself post your code in inpastebin.com pastebin.com n refer us the link so that we can verify your code, and help you solve the riddle. Thanking You Utsav Banerjee
Sahil tell m e the code of this 1 23 456 7 8 9 10
Bindu Kamboj #include v oid oid m ain() { int i,j,a=1; for(i=1;i<=4;i++) { for(j=1;j +)>
sridhar The credit of thi s post goes to Utsav Ba nerjee.. Good Good work Utsav! Editor, Interview Mantra
Haemobindium please tell m e the c code for the following pa ttern ***** **** *** ** *
Aarthi want in java programming...
Ridzi0207 plz tell me the code for ******* ******* *** * *** *******
ankita srivastava #include #include v oid oid m ain() {
2/29/12
10 Challenging star pattern programs in C | Interview Mantra int i,j,k,l,m,n,o;{ for(i=0;i<=1;i++){printf("\n"); for(j=0;j<=6;j++) printf("*");}for(k=0;k<=1;k++){printf("\n");for(l=0;l<=1+k;l++)printf(" ");for(m=0;m<=22*k;m++)printf("*");}printf("\n ***\n");for(o=0;o<=6;o++){printf("*");}}getch();}
Nkkoolguy * **
* **** * ** * ******** * ** * **** * ** *Plz tell the code to get this pa ttern
Bhomit Davara Give me the code of of following pattern : when we input : 3 6 5 4 3 2
1
Bindu Kamboj #include v oid oid m ain() { int i,j,a=6; for(i=1;i<=3;i++) { for(j=1;j { printf ("%d" ("%d",a ,a ); a--; } printf("\n"); } getch(); }
Ajay please giv m e the code code for followin followin g pattern! 1 11 21 1211 111221 312211 13112221
Grissar Would Wo uld someone be able to help with creating a hollow triangle in Java looking looking l ike this: ----*-------*-*-----*---*---*-----*-********* Where the - equals equals a space. A user enters a number and the tria ngle heigh t = the number. I have this code so far but I can't get get any f urther. Not even sure if I'm on the right track any more: http://pastebin.com/rUrKaVW5 Thanks in advance.
Grissar The drawing didn't come out ok. So, here's a ph oto oto..
2/29/12
10 Challenging star pattern programs in C | Interview Mantra giv e me the code of of following pattern 1 01 101 0101 10101
Bschinku thanx dear
Sudhir please can y ou provide the code code for following pattern i n C++ H
H
EEEE E L
L
O H
L
OHHHHH
E
L
OOOOH EEEE E
L
O
L OH
H
E
L
L
O
H
EEEE E
L
OH
O
H
LLLLL
E
LLLLL
OH L
H
E
L
L O
OH
OOOOO
its a l ittle distorted distorted but you you mu st have un derst derstoo ood d what i am trying to printcan m ail m e at [email protected]
Dsasd #include v oid oid m ain() { pri nt f("H H
H
E
prin tf(" L
EEEE E L
L
OOOOH OOOO H
H
E
L
L
O
OH
L \n"); L
O
O
pri nt f("
OHHHHH OHHHHH
EEEEE
L
L
O
H
EEEE E
OH
H
E
L
OH\n"); H
E
L
L
O
OH
LLLLL
LLLLL
OOOOO\n"); OOOO O\n");
}
siva so diff to get!!!
Manish Praja Prajapati1991 pati1991 please give me help for printin g below pattern. pattern. if inputn is 5 then 1
2 3
4 5 16 17 18 19 6
15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
KALE SOMNAH PLS tell me code to wether the gi ven stri g s pali oderm or not
Bujji
Aim
:
to find whether given string i s palindrome or not not Input : accept a strin g Output : palindrome or not Program : #include int main (void (void)) { char st[20],rev[20 st[20],rev[20]; ]; int l=0,i; clrscr(); printf("enter a string"); scanf("%s",&st); for(;st[l]!='\0';l++);
/*to
find length of a string*/ for(i =0; =0;i
="" bun ny ="" compar e=""
" if(s t[i]!="rev[i ])
" in put ="" len gth s=""
loop*="" madam="" not="" of="" original="" output:="" palindrome="" palindrome");="" printf("not="" printf("pali ndrome");= ndrome");="" "" rev[i]="st[l-i-1]; str in g*="" th e="" {="" }="" ="" =""
=""
" rev[l]="\0" rev[l]="\0" reverse="" reversed=" reversed=""" srings *=" *=""" string="" ="">
2/29/12
10 Challenging star pattern programs in C | Interview Mantra Mallickanurag25 #include v oid oid m ain() { int r=0,x,y,z; printf("Enter th e num ber to be checked "); scanf("%d",&x); y=x; w hile (x!= (x!=0) 0) { r=(r*10)+(x%10); x=x/10; z=r; } if (y == ==z) z) { printf("the printf(" the given number is a palli ndrome. ndrome.") ");; } else { printf("the printf(" the given number is not a pallin dro drome.") me.");; } }
ankur loved this i s not the optim optim ized code code this wil l use more memory
loveneesh mirror image of this ***** **** *** ** *
Dineshrockzzz8 class pattern1st { public static void main () { for(i nt i = 1 ; i <=5 ; i++) { for(in t j = 1 ; j <= i ; j++) { System.out.prin t( "*" + " " ); } System.out.println(); } } }
Dharmu1994 #include v oid oid m ain() { int n, c, k; printf("Enter nu mber of rows\n"); scanf("%d",&n); for ( c = 1 ; c <= n ; c++ ) { for( k = c ; k <= n ; k++ ) printf("*"); printf("\n"); }
}
loveneesh ***** **** *** ** *
Angad tomar
2/29/12
10 Challenging star pattern programs in C | Interview Mantra for(i=n;i>0;i--) { printf(" "); for(j=1;j<=i;j++) { printf("*"); } printf("\n"); }
loveneesh how can i print th e pattern pattern ***** **** *** ** *
Vjy 1 141 13531 1357531 13531 141 1
jevie mar galaura i ha ve problem in m y codes please sent me and ema il on as terisk pattern s please!!!!! please!!!!!!! !!!!
sushant choudhary code to print the following pattern : 1 131 13531 1357531 13531 131 1
jasleen above is not exact pattern may b some problem problem in printing the pattern is : there is three spaces spaces and then star in first li ne in second line two spaces spaces then star then one space and again star in th ird line one space one one star then three spaces one one star in fourth lin e seven stars.
jasleen can u please give me a coding of this pattern? *
Rajitha 1111111 1221 1331 141 1331 1221 1111111 can a ny one do this????????? this?????????
saurabh heloo friends your mind is very sharp becouse becouse your programin programin g is v ery dilicious
amit sisodiaa this is so goood goood for begainer
2/29/12
10 Challenging star pattern programs in C | Interview Mantra ajit sujit ye s this i s perfect .but .but it will n ot run properly properly so modify it n ow.
accesscode ***** **** *** ** * Try this>>>>>
Himkarjha2042 #include #include v oid oid m ain() { int i,j,; clrscr(); for(i=6;i>0;i--) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } getch(); }
jadoo #include #include #include #include #include #include #include using namespace std; int main() { for(int i=1;i<=5;i++) { for(i nt j=1;j<=i;j++) j=1;j<=i;j++) { cout<<"**"; } cout<=1;i--) { for(int j=i;j>=1;j--) { cout<<"**"; } cout<
nitesh this is the best for for bigners
Ashu thanks . this is very helpful
Mahendra Hey Sushan t Ur Code Code is Here now ,.....Mahendra(Mayur) ,.....Mahendra(Mayur) #include #include void vo id mai n() { int i,j,n; clrscr(); printf(“\n Enter the num ber :”); :”); scanf(“%d”,&n); for(i=n;i>0;i–) {
2/29/12
10 Challenging star pattern programs in C | Interview Mantra printf("*"); } printf("\n"); } for(i=0;i<=n;i++) { for(j=i;j
Aman code for for the patern : 1 26 3 7 10 4 8 11 13 5 9 12 14 15 here it goes: #include #include void vo id mai n() { int i,j,a,n; clrscr(); printf ("\n Enter the no. of lines to be printed."); scanf("%d",&n); for(i=1;i<=n;i++) { printf("\n"); a=i; for(j=1;j<=i;j++) { printf ("%d ",a); ",a); a=a+n-j; } } getch(); } Enjoy budies...;)
Nikhil ***** ** ** ****
rishav sry dere was problm i s pastin g d code,,,,,,,,d code,,,,,,,,dis is is ryt code VIDHYA VIDHYA #include int main() { int k,m,n,i,j, k,m,n,i,j,l; l; printf ("enter the size of the prog:"); scanf("%d",&n); m=n; for(j=1;j<=n;j++) { if((j<=n/2+1)) { k=j*2-1; for(l=1;ln/2+1) { k=m-2; m=k; for(i=1;i<=k;i++) { printf("*"); } printf("\n"); }
2/29/12
10 Challenging star pattern programs in C | Interview Mantra { continue; }} return 0; }
rishav dis i s ur code ,,,,,,,,,,,,VID ,,,,,,,,,,,,VIDHYA HYA #include int main() { int k,m,n,i,j, k,m,n,i,j,l; l; printf ("enter the size of the prog:"); scanf("%d",&n); m=n; for(j=1;j<=n;j++) { if((j<=n/2+1)) { k=j*2-1; for(l=1;ln/2+1) { k=m-2; m=k; for(i=1;i<=k;i++) { printf("*"); } printf("\n"); } else { continue; }} return 0; }
supantha kumar pal plz tell m e of this code.. 1 12 123 1234 12345
Samadhan Nirali v oid oid m ain() { int i,j,k=1; for(i=1;i<=5;i++) { for(j=1;j<=k;j++) { printf("%d",j); } k++; printf("\n"); } getch(); }
supantha kumar pal @preethi here is ur programme #include void vo id mai n() { int i,j; for(i=1;i<=5;i++) { printf("\n"); for(j=1;j<=i;j++) printf ("a "); "); } } and ur out put is... a aa aaa aaaa aaaaa
2/29/12
10 Challenging star pattern programs in C | Interview Mantra tell m e the code for a aa aaa aaaa aaaaa
rishav here is your code ,,,,,,,,, ,,,,,,,,, shahna waz #include int main() { int m,i,j,k,p; printf ("enter the size of of the program"); scanf("%d",&m); k=p=m; for(i=0;i
rishav #include int main() { int m,n,i,j; m=6; n=11; for(i=0;i<6;i++) { for(j=0;j<11;j++) { if(i<5&&j<2) printf("*"); else if(i==5) printf("*"); else continue; } printf("\n"); } return 0; } here is code for printin g........... ** ** ** ** ** ***********
rishav #include int main() { int m,i,j; printf ("enter the size of of program \n"); scanf("%d",&m); for(i=0;i
manali plz tell me h ow to print print the follo following wing pattern? ****** ***** **** *** **
2/29/12
10 Challenging star pattern programs in C | Interview Mantra
shahnawaz plz help me to write this program 54321 5432 543 54 5
Saptapratim Saptapra tim Bose for(j=1;j<=5;j++) { for(i=5;i,=j;i--) printf('i"); printf("\n"0; } Reply saptapratim Bo Bose se
Saptapratim Saptapr atim Bose for(j=1;j<=5;j++) { for(i=5;i,=j;i--) printf('i"); printf("\n"); } Reply saptapratim Bos Bosee
jyothi ** ** * ** **
M Subscribe by email
S RSS
Load more comments
Trackback URL http://www.interv
P R E V I O U S P OS OS T : NEXT POST:
Bugs can get you a software job
Interview with The Working Geek