How to get this - some ideas please

This is a discussion on How to get this - some ideas please within the C Programming forums, part of the General Programming Boards category; Write a program to produce the following output: ABCDEFGFEDCBA ABCDEF FEDCBA ABCDE EDCBA ABCD DCBA ABC CBA AB BA A ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    5

    How to get this - some ideas please

    Write a program to produce the following output:
    ABCDEFGFEDCBA
    ABCDEF FEDCBA
    ABCDE EDCBA
    ABCD DCBA
    ABC CBA
    AB BA
    A A

    it should be like a pyramid
    my code is this:

    Code:
    #include <stdio.h>
    int main ()
    {
     char a,b,c;
          for (b=65;b<=70;b++)
          printf ("%c", b);
          for(a=70;a>64;a--)
          printf ("%c", a);
          printf ("\n");
    
          for (b=65;b<=69;b++)
          printf ("%c", b);
          printf ("\n");
    
          for (b=65;b<=68;b++)
          printf ("%c", b);
          printf ("\n");
    
          for (b=65;b<=67;b++)
          printf ("%c", b);
          printf ("\n");
    
          for (b=65;b<=66;b++)
          printf ("%c", b);
          printf ("\n");
    
          for (b=65;b<=65;b++)
          printf ("%c", b);
          printf("\n");
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    printf("     ");
    printf("%c",73);
    printf(" wonder where?\n");
    An experiment.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    5

    Smile

    i used printf("\n"); to get the variables printed in next line after for loop executes so each time i execute a for loop i have to print out the it in new line so that the ABCDEFG will become ABCDEF next line like this untill i get down to letter A. I also want to ask y you used printf("%c",73) can you please explain to me so that i can understand bit much about it.Thanks in advance.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    b<=70
    b<=69
    Consider another loop, which counts backwards.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Project ideas.
    By Wraithan in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-25-2009, 03:29 PM
  2. Ideas, how do you get them? xD
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-22-2009, 02:53 AM
  3. cool ideas for a game
    By Shadow12345 in forum Game Programming
    Replies: 7
    Last Post: 05-18-2004, 08:37 PM
  4. idea's idea's idea's
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-29-2002, 12:30 AM
  5. Small app ideas
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-15-2002, 07:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21