Jan 5, 2012

Program :Make Alphabet Triangle

Program :Make Alphabet Triangle
In This Program I use Nested Loop To Make a Alphabet Triangle check out Program.
 

#include<iostream.h>
#include<conio.h>
int main()
{
for(int i=65; i<75; i++)  //i=65 that in ASCII 65 = A
{ // and 75 is K but it will less than 75 so it print till J
    for(int j=0; j<10-i+65; j++)
    { /* here i set j=0 and j < less than (10 - i) that i set to it decrease one by one so in this I add 65 in i so keep i zero at start and increase one by one */
        cout << (char)i; // to convert int to char so i write (char) before write variable
    }
    cout << endl; // new line use every time it print one alphabets
}
getch();
}


OUTPUT


24 comments:

  1. what about this output?
    A
    AB
    ABC
    ABCD

    ReplyDelete
    Replies
    1. for that try this

      #include
      using namespace std;
      int main()
      {
      int i;
      char j;

      for(i =65; i<=67; i++)

      { for(int j=65;j<=i; j++)

      {
      cout<<j;
      }
      cout <<endl;
      }
      return(0);
      }

      Delete
    2. How about this output using nested loop
      S
      SA
      SAM
      SAMP
      SAMPL
      SAMPLE
      SAMPL
      SAMP
      SAM
      SA
      S
      W
      WO
      WOR
      WORK
      WOR
      WO
      W

      Delete
    3. #include<iostream>
      using namespace std;
      /*
      S
      SA
      SAM
      SAMP
      SAMPL
      SAMPLE
      SAMPL
      SAM
      SA
      S
      W
      WO
      WOR
      WORK
      WOR
      WO
      W
      */

      void designFunction(char myString[],int size){
      for(int i=0;i<size;i++){
      for(int j=0;j<=i;j++){
      cout<<myString[j];
      }
      cout<<endl;
      }
      for(int i=size-2;i>=0;i--){
      for(int j=0;j<=i;j++){
      cout<<myString[j];
      }
      cout<<endl;
      }
      }

      int main(){
      designFunction("SAMPLE",6);
      designFunction("WORK",4);
      return 0;
      }

      Delete
  2. for that try this
    #include"iostream.h"
    main()
    {
    for(int i =65; i<69; i++)
    {
    for(int j=0;j<i-65+1; j++)
    {
    cout << (char)(65+j);

    }
    cout <<endl;
    }
    }

    ReplyDelete
  3. a
    b c
    d e f
    g h i j

    ReplyDelete
    Replies
    1. #include"iostream.h"
      main()
      {
      for(int i=65,k=0; i<69; i++)
      {
      for(int j=0;j<i-65+1; j++,k++)
      {
      cout << (char)(65+k);
      }
      cout <<endl;
      }
      }

      Delete
  4. E D C B A B C D E
    D C B A B C D
    C B A B C
    B A B
    A

    ReplyDelete
  5. #include<iostream>
    using namespace std;
    /*
    E D C B A B C D E
    D C B A B C D
    C B A B C
    B A B
    A
    */
    int main()
    {
    int numofrows = 5;
    for(int i=0;i<numofrows;i++){//5 rows
    for(int j=65+numofrows-1-i;j>=65;j--)
    cout << (char)j;
    for(int k=66;k<66+numofrows-1-i;k++)
    cout << (char)k;
    cout <<endl;
    }
    return 0;
    }

    ReplyDelete
  6. A
    D C B
    E F G H I
    P O N M L K J
    # # # # # # # # #
    J K L M N O P
    I H G F E
    B C D
    A

    ReplyDelete
    Replies
    1. /*
      A
      D C B
      E F G H I
      P O N M L K J
      # # # # # # # # #
      J K L M N O P
      I H G F E
      B C D
      A
      */
      #include<iostream>
      #include<stdlib.h>
      using namespace std;
      main()
      {
      int n=4,k=0,i=0;
      for(i=0;i<n;i++)
      {
      int l=k;
      if(i%2 == 0)
      for(int j=65+k;j<65+l+((2*i)+1);j++,k++)
      cout << (char)j;
      else
      for(int j=64+l+((2*i)+1);j>64+l;j--,k++)
      cout << (char)j;
      cout <<endl;
      }
      cout <<"#########\n";
      for(i=n-1;i>=0;i--)
      {
      int l=k;
      if(i%2 == 0)
      for(int j=64+k;j>64+l-((2*i)+1);j--,k--)
      cout << (char)j;
      else
      for(int j=65+l-((2*i)+1);j<=64+l;j++,k--)
      cout << (char)j;
      cout <<endl;
      }
      }

      Delete
    2. How about this output
      S
      SA
      SAM
      SAMP
      SAMPL
      SAMPLE
      SAMPL
      SAM
      SA
      S
      W
      WO
      WOR
      WORK
      WOR
      WO
      W

      Delete
    3. This comment has been removed by the author.

      Delete
  7. #include
    void main()
    {
    int i,x=0;
    char j='A';
    for(i =65; i<69; i++)

    { for(x=65;x<i+1; x++)

    {
    j=x;

    cout<<j<<'\t';
    }
    cout<<'\n';

    }
    }



    This gives output as
    A
    A B
    A B C
    A B C D

    increase limit of i to get more.
    Cheers :)

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int x=0,y,z;
      char c='a';

      for(x=0;x<=5;x++)
      {
      for(z=x;z<=5;z++)
      {
      printf(" ");
      }
      for(y=x;y>=0;y--)
      {

      printf("%c ", c);
      c++;
      printf(" ");
      }
      printf("\n");
      }

      return 0;


      out put
      }
      ................a
      ...............b c
      ..............c d e
      .............f g h i
      ............j k l m n
      ...........o p q r s t

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. /*
    A
    A B A
    A B C B A
    A B C D C B A
    A B C D E D C B A
    */


    #include
    using namespace std;

    int main() {
    const int _A = 65;
    for(int i=0;i<5;i++){
    for(int j=0;j=0;k--){
    cout << (char)(_A+k)<<" ";
    }
    cout << endl;
    }
    return 0;
    }

    ReplyDelete
  12. how to make
    a b c d e
    a b c d
    a b c
    a b
    a

    ReplyDelete
    Replies
    1. #include "iostream"
      using namespace std;

      int main() {
      const int _A = 97;
      for(int i=0;i<5;i++){
      for(int j=0;j<5-i;j++){
      cout << (char)(_A+j)<<" ";
      }
      cout << endl;
      }
      return 0;
      }

      output

      a b c d e
      a b c d
      a b c
      a b
      a

      Delete
  13. A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. how to learn braille for blind

    ReplyDelete