How to print the following triangle in C.?
-
Its an equilateral triangle with numbers as follows :- 1 121 12321 1234321 123454321
-
Answer:
include<stdio.h> void main() { int i,j; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",j); } for(j=i-1;j>=1;j--) { printf("%d",j); } printf("\n"); } getch(); }
neville at Yahoo! Answers Visit the source
Other answers
Like this: /* To display: 1 121 12321 1234321 ... */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int i,n,m,k; char *s, *spaces; if ((argc < 2) || (sscanf(argv[1],"%d",&n) != 1) || ((n = abs(n)) > 9)) { printf("usage : %s <n>\n",argv[0]); puts(" where n is an integer, and |n| < 10"); return -1; } spaces = s = calloc(n, sizeof(char)); memset(spaces, ' ', n-1); for (m = i = k = 1; m <= n; m++, spaces++, i = k = 1) { printf("\n%s",spaces); do { printf("%d",i); if (i == m) k = -1; } while ((i += k) != 0); } free(s); return 0; }
include <stdio.h> void main() { int i,j,k; for (i = 1; i <= 11; i=i+2) { for (j = 1,k=i; j <= i; j++,k--) { if (i == 1) printf("%d", j); else if (j <= i / 2) printf("%d", j); else printf("%d", k); } printf("\n"); } }
Related Q & A:
- How to print a large image in C#?Best solution by Stack Overflow
- How to Convert Code from VB to C++?Best solution by Stack Overflow
- How can I convert Matlab code to c#?Best solution by Stack Overflow
- How to convert xml to json in c#?Best solution by Stack Overflow
- How to convert this curl command in c#?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.