Thread: how to print pattern

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    81

    how to print pattern

    Hi

    I want to print pattern something like

    7, 8, 9, 10

    4, 5, 6

    2, 3

    1

    Code:
    #include<stdio.h>
    
    int main ()
    {
        int n;
        
        for ( n = 0; n <11; n++)
        {
            if (n  > 6)
            {
                printf ("%d ", n);
            }
        }
            return 0;
    }
    7 8 9 10
    I do not understand what to do next

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Better variable names to start with.

    This prints information about the structure of the shape you want
    Code:
    for ( row = 0, items_on_row = 4 ; row < 3 ; row++, items_on_row-- ) {
      printf("Row %d will have %d numbers\n", row, items_on_row );
      for ( n = 0 ; n < items_on_row ; n++ ) {
        printf("%d, ", n );
      }
      printf("\n");
    }
    Now, think about how you can replace printing n, with printing some other value derived from the variables you have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program to print pattern
    By meitsgaurav in forum C Programming
    Replies: 4
    Last Post: 12-24-2017, 06:03 AM
  2. print c pattern
    By surbhijain93 in forum C Programming
    Replies: 7
    Last Post: 03-11-2015, 12:32 PM
  3. Replies: 15
    Last Post: 06-13-2012, 12:34 PM
  4. Replies: 10
    Last Post: 02-19-2010, 07:50 PM
  5. How do I print a pattern flush right?
    By Basia in forum C Programming
    Replies: 5
    Last Post: 06-11-2002, 07:15 AM

Tags for this Thread