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 A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A

Questions by vrijesh28

Showing Answers 1 - 9 of 9 Answers

ravi_529

  • Dec 24th, 2007
 

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.  

  Was this answer useful?  Yes

jintojos

  • May 23rd, 2008
 

Code
  1. #include<conio.h>

  2.   #include<stdio.h>

  3.   #include<string.h>

  4.   void main()

  5.    {

  6.      char arr[]="ABCDEFG";

  7.      int i,j,length=strlen(arr);

  8.      clrscr();

  9.      while(length>0)

  10.         {

  11.                 for(i=0;i<length;i++) printf(" %c",arr[i]);

  12.                 for(j=length-2;j>=0;j--)  printf(" %c",arr[j]);

  13.                 printf("n");

  14.                 length--;

  15.         }

  16.      getch();

  17.    }

  18.  

  Was this answer useful?  Yes

Code
  1. #include<stdio.h>

  2. int main()

  3. {

  4.     /*This code is for any input upto 'Z' from 'A' */

  5.     char i, j, k;

  6.     int a;

  7.     scanf(" %c", &j);

  8.     for (a = j; a <= j; a++) {

  9.         for (i = 'A'; i <= a; i++)

  10.             printf("%c", i);

  11.         for (k = a - 1; k >= 'A'; k--)

  12.             printf("%c", k);

  13.     }

  14.     printf("n");

  15.     for (a = j - 1; a >= 65; a--) {

  16.         for (i = 'A'; i <= a; i++)

  17.             printf("%c", i);

  18.         for (k = a; k >= 'A'; k--)

  19.             printf("%c", k);

  20.         printf("n");

  21.     }

  22.     return 0;

  23. }

  24.  

GNANAPRAKASH.S

  • Aug 9th, 2011
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {

  5.     int i, j, k, n;

  6.     char a[30];

  7.     clrscr();

  8.     scanf("%d", &n, printf("Enter the number of lines upto alpahbets:"));

  9.     for (i = n; i >= 1; i--) {

  10.         for (j = 1; j <= i; j++) {

  11.             a[j] = 64 + j;

  12.             printf("%c", a[j]);

  13.         }

  14.         for (k = j - 1; k >= 1; k--) {

  15.             printf("%c", a[k]);

  16.         }

  17.         printf("

  18.    ");

  19.     }

  20.     getch();

  21. }

  22.  

  Was this answer useful?  Yes

Code
  1. #include

  2. #include

  3. using namespace std;

  4. int main()

  5. {

  6.     char a[] = "abcdefg";

  7.     char b[] = "fedcba";

  8.     cout <<< int m, n;

  9.     m = strlen(a);

  10.     n = strlen(b);

  11.     for (int i = 0; i cout < cout << int k = 1; while (m > 1 && k

  12.   {                                            

  13.     int l = 0; for (int i = 0; i cout < for (int i = k; i cout < cout < m--; k++;

  14.   }

  15.     cin >> z; return 0;

  16. }

  17. <<<

  18.  

  Was this answer useful?  Yes

This one works

Code
  1. #include<iostream>

  2.  

  3. #include<cstring>

  4.  

  5. using namespace std;

  6.  

  7. int main()

  8. {

  9.  

  10.     char a[] = "abcdefg";

  11.  

  12.     char b[] = "fedcba";

  13.  

  14.     cout << a << b << endl;

  15.  

  16.     int m, n;

  17.  

  18.     m = strlen(a);

  19.  

  20.     n = strlen(b);

  21.  

  22.     for (int i = 0; i < m - 1; i++)

  23.  

  24.         cout << a[i];

  25.  

  26.     cout << b << endl;

  27.  

  28.     int k = 1;

  29.  

  30.     while (m > 1 && k < n)

  31.     {

  32.  

  33.         int l = 0;

  34.  

  35.         for (int i = 0; i < m - 2; i++)

  36.  

  37.             cout << a[i];

  38.  

  39.         for (int i = k; i < n; i++)

  40.  

  41.             cout << b[i];

  42.  

  43.         cout << endl;

  44.  

  45.         m--;

  46.  

  47.         k++;

  48.  

  49.     }

  50.  

  51.     return 0;

  52.  

  53. }

  54.  

  Was this answer useful?  Yes

Anil

  • Oct 7th, 2011
 

Code
  1. #include<stdio.h>

  2. #include<conoio.h>

  3. void main()

  4. {

  5.     int len, i, j, k;

  6.     char a[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };

  7.     clrscr();

  8.     len = a.count();

  9.     for (i = 0; i < len; i++) {

  10.         for (j = 0; j < len - i; j++) {

  11.             printf(a[j]);

  12.         }

  13.         for (k = ((len - 2) - i); k >= 0; k--) {

  14.             printf(a[k]);

  15.         }

  16.         printf("

  17.    ");

  18.     }

  19.     getch();

  20. }

  21.  



  Was this answer useful?  Yes

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.  

  Was this answer useful?  Yes

Jimmy Jack

  • Apr 25th, 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.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions