Thread: Number pattern program help

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    8

    Post Number pattern program help

    HI. i am new in c programming.
    Please help me making a program to print this


    Code:
        0
       101
      21012
     3210123
    432101234

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Announcements - C Programming

    I dun the furst rowe four ewe
    Code:
    #include <stdio.h>
    int main ( ) {
        printf("      0\n");
        return 0;
    }
    Seriously, can you even manage
    1
    2
    3
    4


    or even
    1
    12
    123
    1234


    Either would be useful in showing us what you're actually capable of, as opposed to merely being lazy and hoping for someone to do all the work for you.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    8
    I hav to make a lot of programs so im just asking if anyone can help.

    I don want you to write the full program. you can just provide me main loop statements if you hav time.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Sorry, but if you can do

    1
    12
    123
    1234

    Then you already have in your own words - the main loop, and you're at least half-way to solving the problem.

    And you've no idea how many people roll through here claiming to "have written code".

    Post your latest best effort, and then we'll help.
    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.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    126
    I'm not that good but I wrote this real quick trying to figure out why mine is crashing

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    
    {
    int row=0, column=0, j=1, k=0;
    
    while (row<8){ 
    k=row-8;
    while(k<8){
    
    printf(" ");
    k++;
    }
    k=0;
    column=0;
    j=row+1;
    
    
        do{
            if (column<(2*row+1)/2){ 
            printf("%d", (j++)%10);
           
            }else{
            printf("%d", (j--)%10);
            }column++;
           
            }while (column<row*2+1);
       
        printf("\n"); 
        row++;
    }
    
    getch();
        }
    I didn't try to compile I just wrote this in the text box

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    @Sorinx - it looks like a good effort, but please refrain from posting something close to a complete answer before the OP has even posted a line of code.

    Otherwise, there is no learning (for the OP), with the possibly exception that it is sometimes possible to get someone else to do homework for you.
    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.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by nsriv View Post
    I hav to make a lot of programs so im just asking if anyone can help.

    I don want you to write the full program. you can just provide me main loop statements if you hav time.
    The best way to handle these things is first, take a pen and paper, and BECOME the tip of the pen. Print out the digits slowly, and watch the patterns that develop. That will be the core of your logic. May take a few/several times, but those patterns will emerge.

    In your program, start with a basic two for loops, one for the rows and an inner nested for loop, for the printing of each digit or space, in the columns of the print out.

    If you get stuck, post what you have, and we'll make suggestions from there. It is UP TO YOU to post code, before we get into helping you with code. Sometimes we jump the gun, but that's the general rule.

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    8
    Sorinx
    thanks for the help.. only zeros r missing in the output but now i can make the program.. thanks..

    Salem and Adak
    thanks for the advice..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. odd and even number pattern
    By christianB in forum C Programming
    Replies: 31
    Last Post: 07-18-2011, 01:04 PM
  2. Replies: 3
    Last Post: 12-15-2010, 01:35 AM
  3. Hmm.. Ai? Finding the pattern in number squences?
    By Zeusbwr in forum C++ Programming
    Replies: 8
    Last Post: 04-02-2005, 06:13 PM
  4. Replies: 5
    Last Post: 05-25-2004, 04:36 PM
  5. Write a program that prints a pattern of asterisks?
    By Basia in forum C Programming
    Replies: 2
    Last Post: 06-01-2002, 05:56 PM