c program to print patterns of numbers and stars

Page 1 of 21

Search
Search this site: Home C Programming Tutorials C Graphics source codes

Search
Submit Program

Quick navigation
C Mouse Programs C program examples C Source codes Java programs graphics.h C graphics programs conio.h math.h dos.h

c programming examples
• • • • • • • • • • • • • • Hello world Print Integer Addition Add, subtract, multiply and divide Check vowel Leap year Add digits Factorial Add n numbers Swapping Reverse number Palindrome number Print Pattern Diamond

http://www.programmingsimplified.com/c-program-print-stars-pyramid

16/09/2011

c program to print patterns of numbers and stars

Page 2 of 21

• Prime numbers • Find armstrong number • Generate armstrong number • Fibonacci series • Print floyd's triangle • Print pascal triangle • Addition using pointers • Maximum element in array • Minimum element in array • Linear search • Binary search • Reverse array • Insert element in array • Delete element from array • Bubble sort • Insertion sort • Selection sort • Add matrices • Subtract matrices • Transpose matrix • Multiply two matrices • Print string • String length • Compare strings • Copy string • Concatenate strings • Reverse string • Find palindrome • Delete vowels • C substring • Sort a string • Remove spaces • Change case • Swap strings • Character's frequency • Read file • Copy files • Merge two files • List files in a directory

©2011 Programming Simplified Home | Contact Us | Feedback | Links | Sitemap

http://www.programmingsimplified.com/c-program-print-stars-pyramid

16/09/2011

row <= n . Most of these c programs involve usage of nested loops and space.   printf("Enter the number of rows in pyramid of stars you wish to see " scanf("%d". These codes illustrate how to create various patterns using c programming. n.&n).com/c-program-print-stars-pyramid 16/09/2011 . row++ ) { for ( c = 1 . temp. star or characters is a way of arranging these in some logical manner or they may form a sequence.c program to print patterns of numbers and stars Page 3 of 21 • Delete file • Random numbers • Add complex numbers • Print date • Get ip address • Shutdown computer Home → C programming → Programs → c program to print patterns of numbers and stars c program to print patterns of numbers and stars These program prints various different patterns of numbers and stars.   for ( row = 1 . A pattern of numbers. c < temp .programmingsimplified.h>   main() { int row.h> #include<conio. c++ ) printf(" "). * *** ***** ******* ********* We have shown five rows above.   temp = n. Please see the complete page and look at comments for many different patterns. in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.   temp--. c. C code #include<stdio.   http://www. Some patterns are symmetrical while other are not. Some of these patterns are triangles which have special importance in mathematics.

  printf("\n").   for ( c = 1 . scanf("%d".h>   main() { int n.   printf("Enter number of rows\n"). } Output: Consider the pattern * ** *** **** ***** to print above pattern see the code below: #include<stdio. k. }   return 0.c program to print patterns of numbers and stars Page 4 of 21 for ( c = 1 . c++ ) { for( k = 1 .1 . return 0. k <= c .&n). k++ ) printf("*").com/c-program-print-stars-pyramid 16/09/2011 . } For more patterns or shapes on numbers and characters see comments below and also see codes on following pages: http://www. c. }   getch(). c <= n .   printf("\n").programmingsimplified. c++ ) printf("*"). c <= 2*row .

programmingsimplified. k. c). c++ ) printf(" ").com/c-program-print-stars-pyramid 16/09/2011 .   scanf("%d".   space = 0. c <= space . space. &n).22:04 http://www.c program to print patterns of numbers and stars Page 5 of 21 Floyd triangle Pascal triangle » Comments #1 Guest : i need a code for this pattern.17:06 #3 Guest : thanks for the patterns it thanks for the patterns it really helped me a lot. k >= 1 .h>   main() { int n. }   return 0. k-. 12345 1234 123 12 1 26/08/2011 .12:35 #2 adminPs : number pattern c code #include<stdio.   printf("\n").   for ( c = 1 .) { for ( c = 1 . c. } 26/08/2011 .   for ( k = n .   space++. c++) printf("%d". c <= k . 23/08/2011 .

) { for ( c = 1 . &n). c <= k .18:07 #5 adminPs : c program for character pattern #include<stdio. c. space = 0.programmingsimplified.   space++. int n.com/c-program-print-stars-pyramid 16/09/2011 .h>   main() { char ch = 'A'. c++) printf(" "). }   return 0.21:29 #6 Guest : c language diamond pattern of stars 20/08/2011 . k >= 1 . ch = 'A'. k.c program to print patterns of numbers and stars Page 6 of 21 #4 Guest : i need code of this pattern A B C D E F G H A B C D E F G A B C D E F A B C D E A B C D A B C A B A 20/08/2011 . }   printf("\n").   for ( c = 1 . ch). c <= space .14:51 http://www. ch++.   for ( k = n . k-.   scanf("%d". } 20/08/2011 . c++ ) { printf("%c ".

}   return 0. } 20/08/2011 . c <= n .   for ( c = 1 . num = 1. &n).09:48 #8 Guest : please help give me source code 1 01 010 1010 10101 19/08/2011 .programmingsimplified. k <= c .c program to print patterns of numbers and stars Page 7 of 21 #7 adminPs : diamond pattern Diamond pattern 26/08/2011 .com/c-program-print-stars-pyramid 16/09/2011 . } printf("\n"). k.h>   main() { int n. num). c. k++ ) { printf("%d".08:43 #10 Guest : can you write code for this p pr pro prog http://www.   if ( num == 0 ) num = 1. else num = 0.17:38 #9 adminPs : c program to print pattern #include<stdio. c++ ) { for ( k = 1 .   scanf("%d".

}   return 0.20:40 #13 adminPs : c program to print number pattern #include<stdio. k <= c .21:20 #11 adminPs : pattern for string Just input the string and press enter.21:59 #12 Guest : c programming code please get me the code of the c program to get the output as follows: 1 121 12321 1234321 123454321 18/08/2011 . c++ ) { for( k = 0 .   printf("Enter a string\n"). string[k]).c program to print patterns of numbers and stars Page 8 of 21 progr progra program 18/08/2011 . k++ ) { printf("%c". } 18/08/2011 .h>   main() { char string[100].programmingsimplified. #include<stdio.   length = strlen(string).h>   http://www.   for ( c = 0 . int c. corresponding pattern will be printed. length.h> #include<string. gets(string).com/c-program-print-stars-pyramid 16/09/2011 . k. c < length . } printf("\n").

c <= n . } 18/08/2011 .   x = n. }   x--. x). c.   main() { int n. x.   for ( k = 1 .1 . num = 1.programmingsimplified. x = 1.   scanf("%d".22:10 #14 Guest : c++ code to print pattern 1 1 12 21 12321 17/08/2011 . x).   for ( k = 1 . k <= c . c. k++ ) { printf("%d".19:15 #15 adminPs : c++ code to print pattern #include<iostream>   using namespace std. k++ ) { x--. c <= k . k. &n).c program to print patterns of numbers and stars Page 9 of 21 main() { int n. space. http://www.com/c-program-print-stars-pyramid 16/09/2011 . c++ ) { cout << num.   cin >> n. x = 1. k <= n . x++. printf("%d". k.   for ( c = 1 . c++ ) { for ( k = 1 . k <= c . }   return 0. k++ ) { for ( c = 1 . }   printf("\n").

} } else { num--. } 18/08/2011 .17:14 #16 Guest : may i get its source code 1 232 34543 4567654 567898765 16/08/2011 . c++ ) cout << " ". http://www.   scanf("%d". c <= k . } }   printf("\n").   space = n . c++ ) { cout << num.1 .1. c++ ) { cout << num.programmingsimplified. d.c program to print patterns of numbers and stars Page 10 of 21 num++. space.21:34 #17 adminPs : c code for number pattern #include<stdio. }   num--.h>   main() { int n.   for ( c = 1 . num--. c. }   return 0.&n).   x--. num--.com/c-program-print-stars-pyramid 16/09/2011 .3 . for ( c = 1 . c <= 2*x . num = 1. num = 1.   if ( k != n ) { for ( c = 1 . c <= k .

17:53 #19 adminPs : c code for star pattern #include<stdio. num--. for ( c = 1 . k. scanf("%d". d++ ) { num = d.programmingsimplified.c program to print patterns of numbers and stars Page 11 of 21   for ( d = 1 .com/c-program-print-stars-pyramid 16/09/2011 . } num--.   for ( c = 1 .   printf("Enter number of rows\n"). num). } 18/08/2011 . c++ ) { printf("%d". c. num--. c <= d . r. c++ ) printf(" ").   for ( c = 1 . http://www. } printf("\n"). num).17:17 #18 Guest : how to print this pattern ******* ***S*** **SSS** *SSSSS* where S represents Space ******* *** *** ** ** * * 13/08/2011 .&n).   space--. c < d .   }   return 0. num++. d <= n . c <= space . space. c++) { printf("%d".h>   main() { int n.

programmingsimplified.   printf("\n"). } 13/08/2011 . instead of the statement space=2*k-1. c++ ) printf("*"). 22/08/2011 . }   return 0. k <= n . c <= r .com/c-program-print-stars-pyramid 16/09/2011 .13:01 #22 Guest : code guys i need the code for this * ** *** **** ***** http://www.   printf("\n"). r = n-1.c program to print patterns of numbers and stars Page 12 of 21   space = 1.1 .19:17 #20 Guest : Doubt In the program.   for( c = 1 . c <= r . k++ ) {   for( c = 1 . space+=2. .   space = 2*k-1.   for( c = 1 . c++ ) printf("*"). c++ ) printf(" "). ? 22/08/2011 . can we go for the statement. r--.   for ( c = 1 . c <= space .09:47 #21 adminPs : sure You can use but don't forget to initialize variable space to one. c++ ) printf("*"). c <= 2*n .   for ( k = 2 .

scanf("%d". c. c. scanf("%d". k <= n . } 13/08/2011 . k++ ) { for ( c = 1 .h>   main() { int n.   space = n. c++ ) printf("*").   printf("Enter number of rows\n"). }   return 0.&n).   for( c = 1 .   printf("Enter number of rows\n").com/c-program-print-stars-pyramid 16/09/2011 .   printf("\n").   space--. c <= k .&n).17:15 #23 adminPs : star pattern source code #include<stdio. c < space .programmingsimplified.17:29 #24 Guest : i need a program to draw the below patern 1 22 333 4444 55555 12/08/2011 . c++ ) printf(" ").h>   main() { int n. k.18:48 #25 adminPs : number pattern source code #include<stdio. k.c program to print patterns of numbers and stars Page 13 of 21 13/08/2011 .   http://www.   for ( k = 1 . space.

}   return 0.07:31 #28 Guest : need a code in c to print below pattern i want a code to print stars like below * ** *** **** *** ** * 09/08/2011 .20:14 #27 adminPs : Floyd's triangle This pattern is Floyd's triangle see Floyd's Triangle code. } 12/08/2011 . c). k <= c .com/c-program-print-stars-pyramid 16/09/2011 .20:13 #26 Guest : need help i need program to print the following pattern :: 1 23 456 7 8 9 10 11/08/2011 . k++ ) printf("%d".c program to print patterns of numbers and stars Page 14 of 21 for ( c = 1 .programmingsimplified.   printf("\n"). c <= n .21:46 #29 adminPs : stars pattern using c programming #include<stdio. c++ ) { for( k = 1 . 12/08/2011 .h>   main() { http://www.

  space = n.22:38 #30 Guest : GET ME THE CODE OF A PROGRAM GET ME THE CODE OF A PROGRAM TO GET OUTPUT AS FOLLOWS: * *A* *A*A* *A*A*A* 09/08/2011 .h>   main() { int n. scanf("%d". c++) { for( k = 1 . } 09/08/2011 .   printf("Enter number of rows\n"). c <= n .17:21 #31 adminPs : code to print pattern of stars and numbers #include<stdio. c. scanf("%d". k++) { printf("*"). k <= c . }   return 0. k < space .   for ( c = 1 . k-.   for ( k = 1 .   printf("Enter number of rows\n"). k++ ) printf("*").   printf("\n").com/c-program-print-stars-pyramid 16/09/2011 . k++) printf(" "). c <= n . c-. k.   printf("\n"). }   for ( c = n . c++) { for ( k = 1 .) { for ( k = c .&n). c >= 0 . k <= c .) printf("*").c program to print patterns of numbers and stars Page 15 of 21 int n. c.2 . k. http://www.   for ( c = 1 .programmingsimplified.&n). space. k >= 0 . count = 1.

scanf("%d".   temp--.com/c-program-print-stars-pyramid 16/09/2011 .   printf("Enter number of rows\n"). temp. c.13:18 #33 adminPs : code for pattern #include<stdio.   temp = n. k. i need this pattern ***** *** ** * 08/08/2011 .15:32 http://www. k <= temp . k++ ) printf("* "). count++.   for ( c = 1 .21:46 #32 Guest : codes for pyramid of stars. }   return 0. } }   printf("\n"). } return 0. } 08/08/2011 . count = 1.&n). c <= n .programmingsimplified. } 09/08/2011 .   printf("\n").h>   main() { int n.c program to print patterns of numbers and stars Page 16 of 21   if ( c > 1 && count < c) { printf("A"). c++ ) { for( k = 1 . space--.

  printf("Enter number of rows\n").   for ( c = 1 .   printf("\n").com/c-program-print-stars-pyramid 16/09/2011 .13:01 #35 adminPs : code #include<stdio. 08/08/2011 . c++ ) { for( k = 1 . }   return 0. k++ ) printf("* ").15:29 #36 Guest : please help i need c program to print no in this format 1 12 123 1234 06/08/2011 .h>   main() { int n.&n). c <= n . k.programmingsimplified. k <= c . } 08/08/2011 .c program to print patterns of numbers and stars Page 17 of 21 #34 Guest : Please post the code for this * ** *** **** Please post the code to print the following shape as soon as possible.13:59 #37 adminPs : source code #include<stdio.h>   main() { http://www. c. scanf("%d".

k <= c .   printf("Enter number of rows\n"). k. c++ ) { for( k = 1 .22:02 #39 adminPs : number pattern code You are right there is no need to use variable number you can use k directly as in code below: #include<stdio. k). c <= n .   printf("\n"). k.   printf("Enter number of rows\n"). c. number++.11:32 #38 Guest : Thanks giving and suggestion Thanks for the pyramid program!! Please help me in the same problem.   printf("\n"). Can't we directly print k directly instead of number(in 2nd inner for loop)? I have tried it but output gives garbage values!!why does this happen? Please help me! 08/08/2011 .   for ( c = 1 . } 07/08/2011 . }   number = 1.c program to print patterns of numbers and stars Page 18 of 21 int number = 1. }   http://www. c <= n . scanf("%d".com/c-program-print-stars-pyramid 16/09/2011 . scanf("%d". c. k++ ) printf("%d ".&n).programmingsimplified. n.   for ( c = 1 . number).h>   main() { int n. k++ ) { printf("%d ". }   return 0. k <= c .&n). c++ ) { for( k = 1 .

scanf("%d".   for ( c = 1 .programmingsimplified. c <= 2*n-k .15:45 #42 Guest : GET THE SOURCE CODE GET ME THE CODE OF A PROGRAM TO GET OUTPUT AS FOLLOWS: ABCDEFEDCBA ABCDE EDCBA http://www.   for ( j = 1 .h>   main() { int n.   printf("Enter number of rows\n").c program to print patterns of numbers and stars Page 19 of 21 return 0.11:53 #41 adminPs : c code to print pattern #include<stdio. c <= j .&n). c. return 0. j <= n . }   getch().   printf("\n"). c++) printf("* "). k = 2. } 08/08/2011 . c++) printf(" "). j++ ) { for ( c = 1 .com/c-program-print-stars-pyramid 16/09/2011 .11:19 #40 Guest : i need a code in C to print pyramid of stars i need a code in C to print stars like this * * * * * * * * * * please help? 05/08/2011 .   k = k + 2. } 09/08/2011 . j.

23:00 #48 Guest : thanks i am searching same and i got 29/06/2011 . i really like it and learned lot from it.. 11/07/2011 ..c program to print patterns of numbers and stars Page 20 of 21 ABCD ABC AB A DCBA CBA BA A 04/08/2011 . please help if possible. second for printing required spaces and last one to print stars ( 2*(row number) ...11:13 #44 Guest : problem Sir i have some problem regarding loop. the loop coding.13:24 http://www. Sometime i cant understand how loop is working and i cant implement it right too.13:52 #47 adminPs : program explanation The first loop is for number of rows.1 ).programmingsimplified.20:46 #43 Guest : thank you i was looking for it 04/08/2011 .. 10/07/2011 .. How can i improve my understanding skill.com/c-program-print-stars-pyramid 16/09/2011 . 29/06/2011 .00:06 #45 Guest : Compliment sir your site is awesome.:) 11/07/2011 .00:02 #46 Guest : help can you explain the code.

programmingsimplified.com/c-program-print-stars-pyramid 16/09/2011 .c program to print patterns of numbers and stars Page 21 of 21 http://www.