59 : C Program to display half triangle/pyramid of alphabets sequence 7

Check out the complete list of c-programs : C Program List    





We have seen how to make a half pyramid (a right angle triangle) using numbers now we have to use alphabets instead. Rows displaying A to H alphabets, to achive this we require two for loops and instead of numbers we print out alphabets, to do this we need to print out char values, and as we know the ascii value of alphabet capital A i.e 65, so i+64 will print values from A ... B ... C when incremented by 1

To get this, we need to have 2 nested loops. One for row and second to print the numbers for the row.

To achive this you need to have 3 nested for loops.

A 

B B 

C C C 

D D D D 

E E E E E 

F F F F F F 

G G G G G G G 

H H H H H H H H




Variables :

i : Datatype int : Used in for loop1.

j : Datatype int : Used in for loop2.



Logic :


    for(i=1;i<10;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("%c ",i+64);   //we print our char i+64 
        }
        printf("\n");
    }







/*
 * 1000+ C programs + tutorials
 *
 * 
 * 57_c_program_to_display_half_pyramid_of_alphabets_sequence_4
 *  
 *
 *
 *  Created on: Oct 22, 2014
 *  Author: Code2care.org
 */

#include 
//#include <conio.h>

void main() {


//    clrscr();

    int i = 0; //for loop1
    
    int j = 0; //for loop2

  
    for(i=1;i<10;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("%c ",i+64);
        }
        printf("\n");
    }
    

//	getch();


}










The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.