Can you make the code for this output?

Discussion in 'C' started by andyfeb, Sep 17, 2007.

  1. andyfeb

    andyfeb New Member

    Joined:
    Sep 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Can you make the code for this output? (using looping, not gotoxy)

    1.
    Input: 4
    Output:
    1
    234
    234
    1
    Input: 5
    Output:
    1
    234
    56789
    234
    1

    2.
    Input: 5 (must odd)
    1
    2 2
    3 1 3
    4 2 2 4
    5 3 1 3 5
    4 2 2 4
    3 1 3
    2 2
    1
     
  2. andyfeb

    andyfeb New Member

    Joined:
    Sep 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I mean

    1.
    Input: 4
    _1
    234
    _1
    Input: 5
    __1
    _234
    56789
    _234
    __1

    2.
    Input: 5
    ____1
    ___2_2
    __3_1_3
    _4_2_2_4
    5_3_1_3_5
    _4_2_2_4
    __3_1_3
    ___2_2
    ____1

    Note: _ is space, don't print it
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    This is your assignment, right? YOU do it. Write some code and post for help with your problems. Before you do anything else, read the "Before you make a query" thread.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I don't understand your first assignment or at least not the logic behind it.
     
  5. andyfeb

    andyfeb New Member

    Joined:
    Sep 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Oh, I'm sorry. I newbie in this forum. I made the code, but I only can made it for 1 variable, I don't know how to make it in number counter.
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,i,j,spasi;
    printf("Input:");
    scanf("%d",&n);
    if(n%2==0)
    	{for(i=n/2;i>=1;i--)
       	{for(spasi=1;spasi<=i-1;spasi++)
          	printf(" ");
          for(j=1;j<=2*(n/2-i)+1;j++)
          	printf("*");
             printf("\n");}
       for(i=1;i<=n/2;i++)
          {for(spasi=1;spasi<=i-1;spasi++)
          	printf(" ");
          for(j=1;j<=2*(n/2-i)+1;j++)
          	printf("*");
             printf("\n");}}
    else
    	{for(i=n/2+1;i>=1;i--)
       	{for(spasi=1;spasi<=i-1;spasi++)
          	printf(" ");
          for(j=1;j<=2*(n/2+1-i)+1;j++)
          	printf("*");
             printf("\n");}
       for(i=1;i<=n/2;i++)
          {for(spasi=1;spasi<=i;spasi++)
          	printf(" ");
          for(j=1;j<=2*(n-i)-n;j++)
          	printf("*");
             printf("\n");}}
    getch();
    }
     
    Last edited by a moderator: Sep 17, 2007
  6. wrecker

    wrecker New Member

    Joined:
    Mar 12, 2007
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Your problem is not understood properly. Rather your inputs given in two posts vary a lot. Which inputs should we consider correct??? THey contrast a lot for input 5....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice