53 : C Program to display star/asterisk triangle sequence 1

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



This is the most favorite program of teachers and you may usually see in these kind of programming papers and praticals.

You need to display the below triagle of stars/asterisks (like a 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 2 nested for loops.

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




Variables :

i : Datatype int : Used in for loop condition.

sum : Datatype int : To hold the sum of 1st 10 natural numbers. Should be initialized to zero



Logic :

The outer i for loop controls the row, and the inner j for loop prints the stars. Note that the loop breaks when j = i

 for(i = 0; i <= 10 ; i++) {
        
        for(j = 0; j <= i; j++) {
            
            printf("* ");
        }
        
        printf("\n");
        
    }







/*
 * 1000+ C programs + tutorials
 *
 * 
 * 53_c_program_to_display_asterisk_star_sequence_1
 *  
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include 
//#include <conio.h>

void main() {


//    clrscr();

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

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