ccplusplus.com
Learn C, C++ Concepts
Monday, September 19, 2011
print pyramid of numbers in c
/************************************************************* * File : print-pyramid-of-numbers.c * Author : Saurabh Gupta * Desc : print pyramid in c * Source : http://saurabhgupta0527.blogspot.com/p/c.html * Created : AM 06:05 19 September 2011 *************************************************************/ #include <stdio.h> void printSpace(int n) { int i; for(i = 0; i<=n; i++) { printf(" "); } } void printPyramid() { int i, j, sp = 4; for(i = 1; i<= 5; i++) { printSpace(sp); for(j = 1; j<= 2*i-1; j++) { printf("%d",j); } printSpace(sp); sp --; printf("\n"); } } int main() { printf ("\n"); printPyramid(); printf ("\n"); return 0; } /* * OUTPUT * [sgupta@rhel55x86 c]$ gcc print-pyramid-of-numbers.c -o print-pyramid-of-numbers [sgupta@rhel55x86 c]$ ./print-pyramid-of-numbers 1 123 12345 1234567 123456789 [sgupta@rhel55x86 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
1 comment:
kritika deep
September 21, 2011 at 2:56 PM
nice example. very short to print the triangle
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
nice example. very short to print the triangle
ReplyDelete