Answered Questions

  • C Program for pyramid

    What will be the code in c to get the following output?A B C D E F G F E D C B AA B C D E F F E D C B AA B C D E E D C B AA B C D D C B AA B C C B AA B B AA A

    Jimmy Jack

    • Apr 26th, 2012

    Code
    1. #include <iostream>
    2. #include <fstream>
    3.  
    4. void display_sequence2(int depth)
    5. {
    6.     int output_count = 0;
    7.     for (int count = depth - 1; count >= 0; --count) {
    8.         for (int index = 0; index <= count; ++index)
    9.             std::cout << (char) ((((output_count++ == 0) || (index == 2)) ? A : a) + index) << " ";
    10.         for (int index = (count == (depth - 1)) ? count - 1 : count; index >= 0; --index) {
    11.             std::cout << (char) ((((output_count++ == 0) || (index == 2)) ? A : a) + index);
    12.             if (index > 0)
    13.                 std::cout << " ";
    14.         }
    15.     }
    16. }
    17.  
    18. int main()
    19. {
    20.     display_sequence2(7);
    21. }
    22.  

    Gaurav Bhadauria

    • Oct 13th, 2011

    Code
    1. int i, j, k;
    2. char a[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
    3.  
    4. for (i = 0; i < 7; i++) {
    5.     for (k = 0; k < 7 - i; k++)
    6.         printf("%c ", a[k]);
    7.     for (j = 7 - (i + 1); j >= 0; j--)
    8.         printf("%c ", a[j]);
    9.     printf("n");
    10. }
    11.