Thread: Need help with starting this question

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    13

    Question Need help with starting this question

    Okay so the question I was assigned was to create a program where the user enters a number to determine how many rows will be printed.

    Ex. User enters 3

    Output (it should look like a diamond but the forum keeps making it look like this):
    1
    121
    12321
    121
    1

    This is what I've gotten so far:

    Code:
    #include <stdio.h>
    
    main(){
    
    
        int i, j, r;
    
    
        printf("Enter number of rows (1-9):");
        scanf("%d", &r);
        for(i=0;i<=r;i++)
        {
            for(j=1;j<=r;j++)
                printf(" ");
    
    
        }
    
    
        return 0;
    
    
    }
    What are some things I need to know in order to complete the question? I am really stumped on this one.
    Last edited by Nick Ryder; 03-22-2017 at 06:35 PM.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Try writing a function to print each line, with the prototype:
    Code:
    void print_line(int size, int high);
    size is the size entered by the user. high is the highest value for the current line.

    The algorithm for print_line would be:
    * print the needed number of spaces (how do you calculate that?)
    * print from 1 to high
    * print from high - 1 down to 1
    * print a newline

    Then your main program would use print_line to print lines with a high from 1 to size and from size - 1 back down to 1.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C, Question About My program. Just Starting
    By shank09 in forum C Programming
    Replies: 6
    Last Post: 03-14-2013, 01:19 PM
  2. Quick pthread question - starting paused/suspended
    By NightWolf8800 in forum C Programming
    Replies: 3
    Last Post: 10-24-2009, 08:15 AM
  3. Just starting to learn C++ Question about classes
    By uraliss in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2006, 03:31 AM
  4. question about reading inputs starting with 0
    By jibbles in forum C Programming
    Replies: 8
    Last Post: 08-09-2004, 03:27 AM
  5. Another windows service question... starting/stopping
    By BrianK in forum Windows Programming
    Replies: 1
    Last Post: 03-20-2003, 12:22 AM

Tags for this Thread