Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- triangle_from_desired_numbers_v1.c
- Task:
- https://web.facebook.com/photo.php?fbid=863006627544618&set=gm.1579899445502233&type=3&theater
- ---------1
- --------212
- -------82128
- ------6821286
- -----068212860
- ----20682128602
- ---8206821286028
- --682068212860286
- -06820682128602860
- 2068206821286028602
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- // Draw n rows of a triangle with numbers
- void draw_trinagle_of_numbers( int n )
- {
- int num[4]={2,8,6,0}; // array of desired digits
- int i,row, index=0, ns, nd; // ns number of spaces, nd number of digits
- // index is for array num[index] that we print
- for (row=0; row<n; row++) // print rows one by one row
- {
- ns = n-row-1; // calculate ns number of spaces
- nd = (2*row+1)/2; // calculate nd number of digits
- for (i=0; i<ns; i++) // print ns spaces " "
- printf("-");
- for(i=0; i<nd; i++) // print nd "%d " numbers
- {
- printf("%d", num[index] );
- if(index>0)
- index--;
- else
- index=3;
- }
- printf("%d", 1 ); // printf digit 1 in middle
- index = 0;
- for(i=0; i<nd; i++) // print nd "%d " numbers
- {
- printf("%d", num[index] );
- if(index<3)
- index++;
- else
- index=0;
- }
- printf("\n");
- }
- }
- int main(void)
- {
- draw_trinagle_of_numbers( 10 );
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement