57 : C Program to display star/asterisk inverted triangle/pyramid sequence 5

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





We have seen pryramids and half inverted pryramid now lets see how we can print an Inverted Pyramid in C programming.

To get this, we need to have 4 nested loops. One for row, second for spaces, third and forth for adding star/asteriks.

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

* * * * * * * * * * * * * * * * * * * 

  * * * * * * * * * * * * * * * * * 

    * * * * * * * * * * * * * * * 

      * * * * * * * * * * * * * 

        * * * * * * * * * * * 

          * * * * * * * * * 

            * * * * * * * 

              * * * * * 

                * * * 

                  * 




Variables :

i : Datatype int : Used in for loop1.

j : Datatype int : Used in for loop2.

k : Datatype int : Used in for loop3.



Logic :


for(i = 10; i >=1 ;--i)
    {
        for(j = 0; j < 10-i ; ++j) {
           printf("  ");
        }
        
        for(k = i; k <= (2*i-1) ;++k) {
        
          printf("* ");
          
        }
        
        for(l =0; l < (i-1) ; ++l) {
        
         printf("* ");   
         
        }
            
      printf("\n");
        
    }







/*
 * 1000+ C programs + tutorials
 *
 * 
 * 56_c_program_to_display_asterisk_star_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
    
    int k = 0; //for loop3
    
    int l = 0; //for loop3

  
    for(i=10;i>=1;--i)
    {
        for(j=0;j<10-i;++j) {
           printf("  ");
        }
        for(k=i;k<=2*i-1;++k) {
          printf("* ");
        }
        for(l=0; l< (i-1); ++l) {
         printf("* ");   
        }
            
        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.