Thread: Need some help on last part of program

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    3

    Need some help on last part of program

    I'm trying to create an output using only odd numbers as input to create the triangle shown below. Does anyone know how? C programming language.

    Code:
    
    #include <stdio.h>
    
    int main() {
        int counter;
        printf("Odd numbers between 1 to 15\n");
    
        /*
         * Initialize counter with 1, and increment it in every iteration.
         * For every value of counter check whether it is odd number or
         * not and print it accordingly
         */
        for(counter = 1; counter <= 15; counter++) {
            /* Odd numbers are not divisible by 2. When an Odd
             number is divided by 2, it leaves 1 as remainder */
            if(counter%2 == 1) {
                /* counter is odd, print it */
                printf("%d ", counter);
            }
        }
    
        return 0;
    }
    


    Need some help on last part of program-triangle-png


  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Notice that there's a pattern between the number of spaces and asterisks in each row. The components of this pattern are related to the input value. It is up to you to uncover this pattern and express it in logic.

    It might help to use a pen and paper to help uncover this pattern and the logic behind it.

  3. #3
    Registered User
    Join Date
    Jan 2017
    Posts
    3
    That sure does help. Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not sure why part of a program isn't working
    By bpj92 in forum C Programming
    Replies: 4
    Last Post: 07-11-2016, 09:49 PM
  2. Help with part of program
    By mytrademark in forum C Programming
    Replies: 3
    Last Post: 10-13-2011, 03:24 PM
  3. why the control goes to else part in this program
    By vapanchamukhi in forum C Programming
    Replies: 2
    Last Post: 01-13-2009, 07:09 AM
  4. Problem with part of program
    By ammochck21 in forum C++ Programming
    Replies: 8
    Last Post: 11-09-2006, 06:45 AM
  5. How do you branch to another part of the program?
    By gcn_zelda in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2003, 12:27 PM

Tags for this Thread