Upload
rrs1988
View
46
Download
2
Embed Size (px)
DESCRIPTION
Star patterns in c
Citation preview
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
1/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
10 Challenging star pattern programs in Cby U TS A V B A N E R JE E on OCTOB E R 1 9 , 2 009
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. 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:
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
Samsung Mobile PhonesDiscover Samsung phones today. All Phones range. Official Site. Visit!
www.Samsung.com
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
2/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
* * * * *
* * *
*
* * *
* * * * *
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
3/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
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; s >= 1; s--) { // Spacing factor
printf(" ");
}
for (j = 1; j <= i; j++) {
printf("%2c", prnt);
}
printf("\n");
--nos; // Controls the spacing factor
}
return 0;
}
Dow n loa d Code
Ba ck to top
2. Write C program to 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", prnt); } for (s = nos; s >= 1; s--) { //The spacing factor
if (c == 4 && s == 1) {
break;
}
printf(" ");
}
for (k = 1; k <= i; k++) {
if (c == 4 && k == 5) {
break;
}
printf("%2c", prnt);
}
printf("\n");
nos = nos - 4; // controls the spacing factor
++c;
}
}
return 0;
}
Dow n loa d Code
Ba ck to top
3. Write C program to print the following pattern:
* *
* *
* * * *
* * * *
* * * * *
* * * *
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
4/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
* * * *
* *
* *
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++) { if ((i % 2) != 0 && (j % 2) != 0) { printf("%3c", prnt); } else if ((i % 2) == 0 && (j % 2) == 0) { printf("%3c", prnt); } else { printf(" "); } } for (s = nos; s >= 1; s--) { // for the spacing factor
printf(" ");
}
for (k = 1; k <= i; k++) { //Joining seperate figures if (i == 5 && k == 1) { continue; } if ((k % 2) != 0) { printf("%3c", prnt); } else { printf(" "); } } printf("\n"); nos = nos - 2; // space control } nos = 1; // remaining half.. for (p = 4; p >= 1; p--) {
for (r = 1; r <= p; r++) { if ((p % 2) != 0 && (r % 2) != 0) { printf("%3c", prnt); } else if ((p % 2) == 0 && (r % 2) == 0) { printf("%3c", prnt); } else { printf(" "); } } for (s = nos; s >= 1; s--) {
printf(" ");
}
for (k = 1; k <= p; k++) {
if ((k % 2) != 0) {
printf("%3c", prnt);
}
else {
printf(" ");
}
}
nos = nos + 2; // space control
printf("\n");
}
return 0;
}
Dow n loa d 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 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 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", prnt);
} else {
printf(" ");
}
}
printf("\n");
nos++;
}
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
5/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
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", prnt);
} else {
printf(" ");
}
}
nos--;
printf("\n");
}
return 0;
}
Dow n loa d Code
Ba ck 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", prnt);
}
for (k = 1; k <= (i - 1); k++) { if (i == 1) { continue; } printf("%2c", prnt); } printf("\n"); nos--; } nos = 1; for (i = 4; i >= 1; i--) {
for (s = nos; s >= 1; s--) {
printf(" ");
}
for (j = 1; j <= i; j++) {
printf("%2c", prnt);
}
for (k = 1; k <= (i - 1); k++) {
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", prnt);
}
}
if ((i % 2) != 0) {
printf("\n");
nos--;
}
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
6/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
}
return 0;
}
Dow n loa d Code
Ba ck 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++) { //The inner loop
printf("%2c", prnt);
}
return 0;
}
int main() {
int i, nos = 5;
//draws the upper triangle
for (i = 1; i <= 4; i++) { triangle(nos, i); //Inner loop construction nos++; // Increments the spacing factor printf("\n"); } nos = 7; //Draws the lower triangle skipping its base. for (i = 3; i >= 1; i--) {
int j = 1;
triangle(nos, i); // Inner loop construction
nos = nos - j; // Spacing factor
printf("\n");
}
return 0;
}
Dow n loa d Code
Ba ck 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("%2c", prnt); } for (s = nos; s >= 1; s--) {
printf(" ");
}
for (k = 1; k <= i; k++) {
if (i == 5 && k == 5) {
continue;
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
7/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
}
printf("%2c", prnt);
}
nos = nos + 2;
printf("\n");
}
nos = 5;
for (i = 2; i <= 5; i++) {
for (j = 1; j <= i; j++) { printf("%2c", prnt); } for (s = nos; s >= 1; s--) {
printf(" ");
}
for (k = 1; k <= i; k++) {
if (i == 5 && k == 5) {
break;
}
printf("%2c", prnt);
}
nos = nos - 2;
printf("\n");
}
return 0;
}
Dow n loa d Code
Ba ck 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", prnt); } for (sp = nosp; sp >= 1; sp--) {
printf(" ");
}
for (k = 1; k <= i; k++) { if (i == 9 && k == 1) { continue; } printf("%2c", prnt); } nos++; nosp = nosp + 2; printf("\n"); } nos = 4; for (i = 9; i >= 1; (i = i - 2)) {
for (s = nos; s >= 1; s--) {
printf(" ");
}
for (j = 1; j <= i; j++) {
printf("%2c", prnt);
}
nos++;
printf("\n");
}
return 0;
}
Dow n loa d Code
Ba ck to top
9. Write a C program to print the following pattern:
*
* * *
* * * * *
* * * * * * *
* *
* * * *
* * * * * *
* * * * * * *
* * * * * *
* * * *
* *
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
8/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
* * * * * * *
* * * * *
* * *
*
Program:
#include
/*
* nos = Num. of spaces required in the triangle.
* i = Counter for the num. of charcters to print in each row
* skip= 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 case of the formation triangle(nos, i, 1); //skip printing one star in the last row. nos = nos - 2; printf("\n"); } nos = 1; for (i = 3; i >= 1; i--) {
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;
}
Dow n loa d Code
Ba ck 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. of characters to print in each 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
9/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
Like
Sort by popular now
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 == 9 && j == 1) { continue; } } if (i == 1 || i == 9) { printf("%2c", prnt); } else if (j == 1 || j == i) { printf("%2c", prnt); } else { printf(" "); } } return 0; } int main() { int i, nos = 0, nosp = -1, nbsp = -1; for (i = 9; i >= 1; (i = i - 2)) {
triangle(nos, i, 0);
triangle(nosp, i, 1);
triangle(nbsp, i, 1);
printf("\n");
nos++;
nosp = nosp + 2;
nbsp = nbsp + 2;
}
nos = 3, nosp = 5, nbsp = 5;
for (i = 3; i <= 9; (i = i + 2)) {
triangle(nos, i, 0);
triangle(nosp, i, 1);
triangle(nbsp, i, 1);
printf("\n");
nos--;
nosp = nosp - 2;
nbsp = nbsp - 2;
}
return 0;
}
Dow n loa d Code
Ba ck to top
Over 1600 professionals follow Interview Mantra.
Enter your email address Send email updates
About the Author: This post was written by Utsav Banerjee. You can reach Utsav
on email at fugitiv [email protected]
2,394 readers have already subscribed to email updates!
Enter your email address:
Subscribe
Tagged as: pattern programs
Showing 1 00 of 1 28 comments
LoginAdd New Comment
tel l me the code of fol lowing
*
***
****
*****
****
***
*
Abiha_kazm i32
Li k e Repl y3 months ago 4 Li k es
Snehalvjadhav
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
10/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
tel l me the code of fol lowing pattern.
*
* *
* * *
* *
*
Li k e Repl y4 months ago 5 Li k es
#inclu de<stdio.h>
main()
{
int i ,j,k,n;
printf(how many l ines you want to 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");
}
}</stdio.h>
Mansi
Li k e Repl y4 months ago i n r epl y to Snehal v jadhav 6 Li k es
give me the code of fol lowing pattern
*
***
*****
*******
abc
Li k e Repl y3 months ago 3 Li k es
void main()
{
int a,b;
a=b=7/2+1;//n=no of rows..n+(n-1)=7(for 4 rows)
for(int i=1;i<=4;i++)
{
for(int j=1;j<=7;j++)
{
i f(j>=a&&j<=b)
print("*");
}
a--;
b++;
}
}
Sarvesh445
Li k e Repl y2 months ago i n r epl y to abc
can u tel l me how to pu t tis pattern
*
* * *
* * * * *
* * *
*
vidhy a
Li k e Repl y8 months ago 7 Li k es
This is code for Loveneesh 's ou tpu t l ike
*****
****
***
**
*
#inclu de
#inclu de
S.V.Ram ana
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
11/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
void main()
{
int i ,j,n;
clrscr();
printf("Enter n valu e");
scanf("%d",&n);
for(i=n;i>0;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Li k e Repl y5 months ago 4 Li k es
how can i print '**'s fou r sides of screen????
example l ike th is............
************************************************************************
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*************************************************************************
can any 1 help me??????please.......
Hari
Li k e Repl y3 months ago 2 Li k es
can U give you r Email id I Wil l Send u program solu tion b-coz content not Fit on i t,,,,,,,,,,,,,,,,If Y ou
have A lready Solved th is problem then V ery Good Try...........
Jay esh5101992sapkale
Li k e Repl y1 month ago i n r epl y to Har i
int first_term=1;
void main()
{
int a[100][100];
int c=1,i=0,j=0,k=0,m=0,n=0,x=0;
clrscr();
printf("Enter Rows and colu mns for the squ are matrix \n");
scanf("%d",&n);
x=n;
while(n>=1)
{
for(k=0;k<n;k++) else{a[k+m][n-1+m]="0;}" else{a[m][k+m]="0;}" for(k="1;k<n;k++)"
i f(first_term){a[k+m][n-1+m]="c++;}" i f(first_term){a[m][k+m]="c++;}">=0;k--)
i f(first_term){a[n-1+m][k+m]=c++;}
else{a[n-1+m][k+m]=0;}
for(k=n-2;k>0;k--)
i f(first_term){a[k+m][m]=c++;}
else{a[k+m][m]=0;}
i f(x==n){
first_term=0;}
n-=2;
m++;
}
for(i=0;i<x;i++) ");}="" ;}="" else{printf("="" for(j="0;j&l t;x;j++)" getch();="" i f(a[i][j]="=0)
{printf("" printf("\n");="" {="" }="" ="" *")=""></x;i++)></n;k++)>
Jay esh5101992sapkale
Li k e Repl y1 month ago i n r epl y to Jay esh51 01 992sapk al e
Remove al l
last l ine from it
Jay esh5101992sapkale
Li k e Repl y1 month ago i n r epl y to Jay esh51 01 992sapk al e
#inclu de <conio.h>
#inclu de <stdio.h>
int first_term=1;
void main()
{
int a[100][100];int c=1,i=0,j=0,k=0,m=0,n=0,x=0;clrscr();
printf("Enter the nu mber of rows and colu mns for the squ are matrix \n");scanf("%d",&n);x=n;
</stdio.h></conio.h>
Jay esh5101992sapkale
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
12/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
Li k e Repl y1 month ago i n r epl y to Har i
Hi Hari ,,,,,Check th is code in c langu age..........i f any Error Plz Fix i t....
Code:
#inclu de <conio.h>#inclu de <stdio.h>int first_term=1;void main(){int a[100][100];int
c=1,i=0,j=0,k=0,m=0,n=0,x=0;clrscr();printf("Enter the nu mber of rows and colu mns for the squ are
matrix \n");scanf("%d",&n);x=n;while(n>=1){for(k=0;k<n;k++)if(first_term){a[m]
[k+m]=c++;}else{a[m][k+m]=0;}for(k=1;k<n;k++)if(first_term){a[k+m][n-1+m]=c++;}else{a[k+m][n-
1+m]=0;}for(k=n-2;k>=0;k--)i f(first_term){a[n-1+m][k+m]=c++;}else{a[n-1+m][k+m]=0;}for(k=n-
2;k>0;k--)i f(first_term){a[k+m][m]=c++;}else{a[k+m][m]=0;}i f(x==n){first_term=0;}n-
=2;m++;}for(i=0;i<x;i++){for(j=0;j<x;j++){ ");} ="" ;}}printf("\n");}getch();}="" else{printf("="" i f(a[i]
[j]="=0){printf("" ="" *")=""></x;i++){for(j=0;j<x;j++){ ></n;k++)if(first_term){a[m]
[k+m]=c++;}else{a[m][k+m]=0;}for(k=1;k<n;k++)if(first_term){a[k+m][n-1+m]=c++;}else{a[k+m][n-
1+m]=0;}for(k=n-2;k></stdio.h></conio.h>
Jay esh5101992sapkale
Li k e Repl y1 month ago i n r epl y to Har i
sorry th is is not su itable.,,,,I wi l l provide in to parts
Jay esh5101992sapkale
Li k e Repl y1 month ago i n r epl y to Jay esh51 01 992sapk al e
void main()
{
for(int i=1;i<=n;i++)//n is any integer valu e
for(int j=1;j<=n;j++)
i f(i==1||i==n||j==1||j==n)
print("*");
}
Sarvesh445
Li k e Repl y2 months ago i n r epl y to Har i
give me the code of fol lowing pattern
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
abc
Li k e Repl y3 months ago 2 Li k es
great
Rohitarg91
Li k e Repl y4 months ago 2 Li k es
give me the code of fol lowing character A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
pls reply sir code
regards
Raj vishwakarma
Rajsharm aj2ee
Li k e Repl y2 months ago 1 Li k e
#inclu de<stdio.h>
#inclu de<conio.h>
void main()
int i ,j,k,l ,a=1,d=2,x;
char p='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++)
{
Bindu Kam boj
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
13/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
printf("%c",p-1);
p--;
}
printf("\n");
}
getch();
}
</conio.h></stdio.h>
Li k e Repl y1 month ago i n r epl y to Rajshar maj2ee
plz someone tel l me program for fol lowing ou tpu t
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
AT UBH BHAWARE
Li k e Repl y7 months ago 3 Li k es
#inclu de<stdio.h>
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");
}
retu rn 0;
}</stdio.h>
Suhani6y adav
Li k e Repl y2 months ago i n r epl y to ATU BH BHAW ARE
plz tel l the code....
1
2 3
4 5 6
7 8 9 10
supantha kum ar pal
Li k e Repl y7 months ago 3 Li k es
#inclu de<stdio.h>
void main()
{
int i ,j,a=1;
for(i=1;i<=4;i++)
{
for(j=1;j<i+1;j++)<br> {
printf("%d",a);
a++;
}
printf("\n");
}
getch();
}</i+1;j++)<br></stdio.h>
Bindu Kam boj
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
14/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
Li k e Repl y1 month ago i n r epl y to supantha k umar pal 1 Li k e
#inclu de<stdio.h>
void main()
{int i ,j,temp=0;
clrscr();
for(i=0;i<n;i++) for(j="0;j&l t;n;j++)" printf("%d",temp);="" temp++;="" {="" }=""></n;i++)></stdio.h>
subbanaidu
Li k e Repl y3 months ago i n r epl y to supantha k umar pal
#inclu de<stdio.h>
main()
{
int n , c, 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");
}
retu rn 0;
}</stdio.h>
Dharm u1994
Li k e Repl y4 months ago i n r epl y to supantha k umar pal
can u please give me a coding of th is pattern?
*
* *
* *
* * * * * * *
jasleen
Li k e Repl y6 months ago 2 Li k es
* *
* *
*
* *
* *
no. of rows to be entered by u ser ?
anony m ous
Li k e Repl y3 months ago 1 Li k e
plz tel l me coding ****** and send me code on my email -id
* * my id [email protected]
* *
******
rashm i
Li k e Repl y4 months ago 1 Li k e
i need simple c program to print l ike a fol lowing pattern
*
* * *
* * * * *
* * *
*
R.Mahalakshm i
Li k e Repl y5 months ago 1 Li k e
class pattern21st
{
pu bl ic static void main ()
{
for(int i = 1 ; i <=5 ; i++)
{
for(int j = 1 ; j <= i ; j++)
{
System.ou t.print( "*" + " " );
}
System.ou t.println();
}
for(int i = 4 ; i >=1 ; i --)
{
for(int j = 1 ; j <= i ; j++)
{
System.ou t.print( "*" + " " );
}
System.ou t.println();
}
Dineshrockzzz8
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
15/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
}
}
Li k e Repl y1 month ago i n r epl y to R.Mahal ak shmi 1 Li k e
plz someone tel l me program for fol lowing ou tpu t
abcdedcba
abcd dcba
abc cba
ab ab
a a
jy otish
Li k e Repl y6 months ago 1 Li k e
plz someone tel l me program for fol lowing ou tpu t
*
* *
* * *
* * * * *
AT UBH BHAWARE
Li k e Repl y7 months ago 1 Li k e
to print as
* * *
* *
*
sai
Li k e Repl y7 months ago 1 Li k e
sir,How can we print stars in a circle?
saurabh chopra
Li k e Repl y7 months ago 1 Li k e
hey i want to print
******
* *
* *
* *
******
tejas chachad
Li k e Repl y1 0 months ago 1 Li k e
#inclu de<stdio.h>#inclu de<conio.h>
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();
}</conio.h></stdio.h>
ankita srivastava
Li k e Repl y6 day s ago i n r epl y to tejas chachad 1 Li k e
plz help mi to write ths pattern program..
*****************
* *
* *
****** ******
1 * *
* *
**** ****
* *
***********
pratik
Li k e Repl y1 1 months ago 1 Li k e
*
* *
* *
* * * * * *
Pram od
Li k e Repl y1 y ear ago 1 Li k e
m athapelo
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
16/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
8 Write a separate algorithm for a program to ou tpu t each of the fol lowing patterns
[N ote: There are fou r triangles of stars label led (a) (b) (c) (d). Each triangle consists of ten l ines of stars.
Starting from l ine 1 to 10, the nu mber of stars
ei ther increases by 1 from 1 to 10
or decreases by 1 from 10 to 1]:
(a) (b) (c) (d)
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
Li k e Repl y1 y ear ago 1 Li k e
A s the au thor of the post , I wou ld l ike to requ est everyone not to ask for ready made codes as I am strictly
against spoon feeding. Please try ou t the problem you rsel f post you r code in pastebin.com n refer u s the l ink so
that we can veri fy you r code, and help you solve the riddle.
Thanking Y ou
Utsav Banerjee
Utsav Banerjee
Li k e Repl y1 y ear ago 1 Li k e
tel l me the code of th is
1
2 3
4 5 6
7 8 9 10
Sahil
Li k e Repl y1 y ear ago 1 Li k e
#inclu de<stdio.h>
void main()
{
int i ,j,a=1;
for(i=1;i<=4;i++)
{
for(j=1;j<i+1;j++) a++;="" getch();="" printf("%d",a);="" printf("\n");="" {="" }="" }="" =""></i+1;j++)>
</stdio.h>
Bindu Kam boj
Li k e Repl y1 month ago i n r epl y to Sahi l
The credit of th is post goes to Utsav Banerjee.. Good work Utsav!
Editor,
Interview Mantra
sridhar
Li k e Repl y2 y ear s ago 1 Li k e
please tel l me the c code for the fol lowing pattern
* * * * *
* * * *
* * *
* *
*
Haem obindium
Li k e Repl y5 day s ago
want in java programming...
Aarthi
Li k e Repl y1 w eek ago
plz tel l me the code for
*******
*******
***
*
***
*******
Ridzi0207
Li k e Repl y1 month ago
#inclu de<stdio.h>
#inclu de<conio.h>
void main()
{
ankita srivastava
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
17/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
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<=2-
2*k;m++)printf("*");}printf("\n ***\n");for(o=0;o<=6;o++){printf("*");}}getch();}</conio.h>
</stdio.h>
Li k e Repl y5 day s ago i n r epl y to Ri dzi 0207
*
* *
*
* * * *
*
* *
*
* * * * * * * *
*
* *
*
* * * *
*
* *
*Plz tel l the code to get th is pattern
Nkkoolguy
Li k e Repl y1 month ago
Give me the code of fol lowing pattern :
when we inpu t : 3
6
5 4
3 2 1
Bhom it Davara
Li k e Repl y1 month ago
#inclu de<stdio.h>
void main()
{
int i ,j,a=6;
for(i=1;i<=3;i++)
{
for(j=1;j<i+1;j++)<br> {
printf("%d",a );
a--;
}
printf("\n");
}
getch();
}</i+1;j++)<br></stdio.h>
Bindu Kam boj
Li k e Repl y1 month ago i n r epl y to Bhomi t Dav ar a
please giv me the code for fol lowing pattern!
1
11
21
1211
111221
312211
13112221
Ajay
Li k e Repl y2 months ago
Wou ld someone be able to help with creating a hol low triangle in Java looking l ike th is:
----*-------*-*-----*---*---*-----*-*********
Where the - equ als a space. A u ser enters a nu mber and the triangle height = the nu mber.
I have th is code so far bu t I can't get any fu rther. N ot even su re i f I'm on the right track anymore:
http://pastebin.com/rUrKaV W5 Thanks in advance.
Grissar
Li k e Repl y2 months ago
The drawing didn't come ou t ok. So, here's a photo.
Grissar
Li k e Repl y2 months ago i n r epl y to Gr i ssar
deepak singla
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
18/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
give me the code of fol lowing pattern
1
01
101
0101
10101
Li k e Repl y2 months ago
thanx dear
Bschinku
Li k e Repl y3 months ago
please can you provide the code for fol lowing pattern in C++
H H EEEEE L L OOOOH H E L L O OH H E L
L O OHHHHH EEEEE L L O OH H E L L O OH
H E L L O OH H EEEEE LLLLL LLLLL OOOOO
its a l i ttle distorted bu t you mu st have u nderstood what i am trying to printcan mail me at
SUDHIR14789@gmail .com
Sudhir
Li k e Repl y4 months ago
#inclu de<stdio.h>
void main()
{
printf("H H EEEEE L L OOOOH H E L L O OH
H E L \n");
printf(" L O OHHHHH EEEEE L L O OH H E L
L O OH\n");
printf(" H E L L O OH H EEEEE LLLLL LLLLL OOOOO\n");
}</stdio.h>
Dsasd
Li k e Repl y1 w eek ago i n r epl y to Sudhi r
so di ff to get!!!
siva
Li k e Repl y4 months ago
please give me help for printing below pattern.
i f inpu tn is 5 then
1 2 3 4 516 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Manish Prajapati1991
Li k e Repl y4 months ago
PLS tel l me code to wether the given strig s pal ioderm or not
KALE SOMNAH
Li k e Repl y5 months ago
A im :
to find whether given string is pal indrome or not
Inpu t
: accept a string
Ou tpu t
: pal indrome or not
Program :
#inclu de<stdio.h>
int main(void)
{
char st[20],rev[20];
int l=0,i ;
cl rscr();
printf("enter a string");
scanf("%s",&st);
for(;st[l ]!='\0';l++); /*to
find length of a string*/
for(i=0;i<l ;i++) &="" *to="" 2="" ;="" a="" break="" break; ="" bu nny="" compare=""
else="" enter="" for(i="0;i&l t;l ;i++)" i f(i="=l) " i f(st[i ]!="rev[i]) " inpu t ="" lengths=""
loop*="" madam="" not="" of="" original="" ou tpu t:="" pal indrome="" pal indrome");="" printf("not=""
printf("pal indrome");="" rev[i]="st[l -i -1]; " rev[l ]="\0" reverse="" reversed="" srings*="" string=""
string*="" the="" {="" }="" ="" ="" ="" =""></l ;i++)></stdio.h>
Bujji
Li k e Repl y3 months ago i n r epl y to KALE SOMN AH 1 Li k e
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
19/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
#inclu de<stdio.h>
void main()
{
int r=0,x,y ,z;
printf("Enter the nu mber to be checked ");
scanf("%d",&x);
y=x;
while (x!=0)
{
r=(r*10)+(x%10);
x=x/10;
z=r;
}
i f (y==z)
{
printf("the given nu mber is a pal l indrome.");
}
else
{
printf("the given nu mber is not a pal l indrome.");
}
}</stdio.h>
Mallickanurag25
Li k e Repl y5 months ago i n r epl y to KALE SOMN AH
th is is not the optimized code th is wi l l u se more memory
ankur loved
Li k e Repl y5 months ago
mirror image of th is
*****
****
***
**
*
loveneesh
Li k e Repl y5 months ago
class pattern1st
{
pu bl ic static void main ()
{
for(int i = 1 ; i <=5 ; i++)
{
for(int j = 1 ; j <= i ; j++)
{
System.ou t.print( "*" + " " );
}
System.ou t.println();
}
}
}
Dineshrockzzz8
Li k e Repl y1 month ago i n r epl y to l ov eneesh
#inclu de<stdio.h>
void main()
{
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");
}
}</stdio.h>
Dharm u1994
Li k e Repl y4 months ago i n r epl y to l ov eneesh
*****
****
***
**
*
loveneesh
Li k e Repl y5 months ago
Angad tom ar
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
20/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
for(i=n;i>0;i--)
{
printf(" ");
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
Li k e Repl y1 month ago i n r epl y to l ov eneesh
how can i print the pattern
*****
****
***
**
*
loveneesh
Li k e Repl y5 months ago
1
1 4 1
1 3 5 3 1
1 3 5 7 5 3 1
1 3 5 3 1
1 4 1
1
Vjy
Li k e Repl y5 months ago
i have problem in my codes please sent me and email on asterisk patterns please!!!!!!!!
jevie m ar galaura
Li k e Repl y5 months ago
code to print the fol lowing pattern:
1
1 3 1
1 3 5 3 1
1 3 5 7 5 3 1
1 3 5 3 1
1 3 1
1
sushant choudhary
Li k e Repl y5 months ago
above is not exact pattern may b some problem in printing
the pattern is :
there is three spaces and then star in first l ine
in second l ine two spaces then star then one space and again star
in th ird l ine one space one star then three spaces one star
in fou rth l ine seven stars.
jasleen
Li k e Repl y6 months ago
can u please give me a coding of th is pattern?
*
jasleen
Li k e Repl y6 months ago
1 1 1 1 1 1 1
1 2 2 1
1 3 3 1
1 4 1
1 3 3 1
1 2 2 1
1 1 1 1 1 1 1
can any one do th is?????????
Rajitha
Li k e Repl y6 months ago
heloo friends you r mind is very sharp becou se you r programing is very di l iciou s
saurabh
Li k e Repl y6 months ago
th is is so goood for begainer
am it sisodiaa
Li k e Repl y6 months ago
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
21/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
ye s th is is perfect .bu t i t wi l l not ru n properly so modify i t now.
ajit sujit
Li k e Repl y6 months ago
* * * * *
* * * *
* * *
* *
*
Try th is>>>>>
accesscode
Li k e Repl y6 months ago
#inclu de<stdio.h>
#inclu de<conio.h>
void main()
{
int i ,j,;
cl rscr();
for(i=6;i>0;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}</conio.h></stdio.h>
Him karjha2042
Li k e Repl y4 months ago i n r epl y to accesscode 1 Li k e
#inclu de
#inclu de
#inclu de
#inclu de
#inclu de
#inclu de
#inclu de
u sing namespace std;
int main()
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
cou t<<"**";
}
cou t<=1;i--)
{
for(int j=i ;j>=1;j--)
{
cou t<<"**";
}
cou t<<endl ;
}
retu rn 0;
}
jadoo
Li k e Repl y6 months ago
th is is the best for bigners
nitesh
Li k e Repl y6 months ago
thanks . th is is very helpfu l
Ashu
Li k e Repl y7 months ago
Hey Su shant Ur Code is Here now ,.....Mahendra(Mayu r)
#inclu de
#inclu de
void main()
{
int i ,j,n;
clrscr();
printf(“\n Enter the nu mber :”);
scanf(“%d”,&n);
for(i=n;i>0;i–)
{
for(j=i ;j<=n;j++)
{
Mahendra
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
22/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
printf("*");
}
printf("\n");
}
for(i=0;i<=n;i++)
{
for(j=i ;j<n-1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
/*
Enter the nu mber :5
*
**
***
****
*****
****
***
**
*
*/
Li k e Repl y7 months ago
code for the patern:
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
here i t goes:
#inclu de
#inclu de
void main()
{
int i ,j,a,n;
clrscr();
printf("\n Enter the no. of l ines 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+n-j;
}
}
getch();
}
Enjoy bu dies...;)
Am an
Li k e Repl y8 months ago
* * * * *
* *
* *
* * * *
Nikhil
Li k e Repl y8 months ago
sry dere was problm is pasting d code,,,,,,,,dis is ryt code V IDHY A
#inclu de
int main()
{
int k,m,n,i ,j,l ;
printf("enter the size of the prog:");
scanf("%d",&n);
m=n;
for(j=1;j<=n;j++)
{
i f((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
rishav
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
23/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
{
continu e;
}}
retu rn 0;
}
Li k e Repl y8 months ago
dis is u r code ,,,,,,,,,,,,V IDHY A
#inclu de
int main()
{
int k,m,n,i ,j,l ;
printf("enter the size of the prog:");
scanf("%d",&n);
m=n;
for(j=1;j<=n;j++)
{
i f((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
{
continu e;
}}
retu rn 0;
}
rishav
Li k e Repl y8 months ago
plz tel l me of th is code..
1
12
123
1234
12345
supantha kum ar pal
Li k e Repl y8 months ago
void main()
{
int i ,j,k=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=k;j++)
{
printf("%d",j);
}
k++;
printf("\n");
}
getch();
}
Sam adhan Nirali
Li k e Repl y4 months ago i n r epl y to supantha k umar pal
@preethi
here is u r programme
#inclu de
void main()
{
int i ,j;
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=i;j++)
printf("a ");
}
}
and u r ou t pu t is...
a
a a
a a a
a a a a
a a a a a
supantha kum ar pal
Li k e Repl y8 months ago
preethi
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
24/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
tel l me the code for
a
a a
a a a
a a a a
a a a a a
Li k e Repl y8 months ago
here is you r code ,,,,,,,,, shahnawaz
#inclu de
int main()
{
int m,i ,j,k,p;
printf("enter the size of the program");
scanf("%d",&m);
k=p=m;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
i f(i<=j)
{
printf("%d",p);
p--;
}}
p=k;
printf("\n");
}
retu rn 0;
}
rishav
Li k e Repl y8 months ago
#inclu de
int main()
{
int 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)
printf("*");
else i f(i==5)
printf("*");
else
continu e;
}
printf("\n");
}
retu rn 0;
}
here is code for printing...........
**
**
**
**
**
***********
rishav
Li k e Repl y8 months ago
#inclu de
int main()
{
int m,i ,j;
printf("enter the size of program \n");
scanf("%d",&m);
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
i f(i<=j)
printf("*");
}
printf("\n");
}
retu rn 0;}
rishav
Li k e Repl y8 months ago
plz tel l me how to print the fol lowing pattern?
* * * * * *
* * * * *
* * * *
* * *
* *
*
m anali
2/29/12 10 Challenging star pattern programs in C | Interview Mantra
25/25www.interviewmantra.net/2009/10/10-star-pattern-programs.html
M Su bscribe by email S RSS
Loa d m or e c om m en t sLoa d m or e c om m en t s
Trackback URL http://www.interviewmantra.net/2009/10/10-star-pattern-programs.html/trackback
P R E V I O U S P O S T : Bugs can get you a software job
N E X T P O S T : Interview with The Working Geek
Li k e Repl y8 months ago
plz help me to write th is program
54321
5432
543
54
5
shahnawaz
Li k e Repl y8 months ago
for(j=1;j<=5;j++)
{
for(i=5;i ,=j;i --)
printf('i ");
printf("\n"0;
}
Reply saptapratim Bose
Saptapratim Bose
Li k e Repl y3 months ago i n r epl y to shahnaw az
for(j=1;j<=5;j++)
{
for(i=5;i ,=j;i --)
printf('i ");
printf("\n");
}
Reply saptapratim Bose
Saptapratim Bose
Li k e Repl y3 months ago i n r epl y to Saptapr ati m Bose
* *
* *
*
* *
* *
jy othi
Li k e Repl y9 months ago