55 : C Program to display star/asterisk triangle sequence 3

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





You need to display the below triagle of stars/asterisks (like a inverted right angle triangle of stars). There are 10 rows and each row has one asterisk less then the above starting from 1 asterisk.

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







/*
 * 1000+ C programs + tutorials
 *
 * 
 * 55_c_program_to_display_asterisk_star_sequence_3
 *  
 *
 *
 *  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

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