Printing a Triangle in C Language...

Today I am back with a New C Program, Which will print an Triangle as below

*
**
***
****
*****
Code:

#include
#include

void main()
 {
  int i, j;
  clrscr();
  for(i=0;i<=5;i++)
   {
     for(j=1;j<=i;j++)
      {
        printf("*");
      } 
     printf("\n");
   }
  getch();
 }
Now Let's Illustrate above code.



  1. First 2 Lines are Pre-Processor Directives as you are already familiar with them. 
  2. We started our Main section of Program. with void main(). Void is being used because we are not going to return any values. 
  3. We have defined two Variables of Integer Type named i and j.
  4. clrscr() -- Clear Screen Function is for Clearing the DOS screen which will appear while we Run program.
  5. Now We take First for Loop here. Which we will use to print New Rows.  Detail : for(i=0;i<=5;i++). [  i=0; Variable i is initialized with Value 0. i<=5; i will continue up to value 5. Because we have to print Asterisks (*) in Five Rows. i++; This Operator is used to Increment value of i by 1 every time.]
  6. Once another for loop is used with Variable j.  We have used this to print Columns. Details : for(j=1; j<=i;j++). [   j=0; Variable is initialized with Value 0. j<=i; j will continue up to value of i. (i.e. According to Rows)  Because we have to print Asterisks (*) according to Number of  Rows. j++; This Operator is used to Increment value of j by 1 every time.]
  7. printf("*"); -- This command will print * in the Screen according to loop mentioned in above (No. 6).
  8. Printf("\n"); -- This command will print new blank line when needed. i.e. According to first for loop. 
  9. getch(); -- This is a function which is an Input Function. We use this for input of Passwords or such data which does not display in screen. We have just used this here to Hold Screen. So that we can see the output.
If you have some questions about above tutorial or other questions, You can comment below or directly mail me at [email protected]. I will surely help you. Its my promise. Lets Enjoy Learning together....

Ehhhh... Happy New Year 2012....

John Bhatt
P.Yar.B Complex

Reactions: 

Happy New Year 2012....

Once again with Image of Last Year, reusing..... Very very happy New Year 2012.....

Reactions: 

Earnings of 2011....

I was writing details from My Mobile. In some advance language Mobile Calender and Contact Sync process was running.  I analyzed my last one Year, i.e. 2011. I have gained/earned something or Lost something.

This makes me to remember controversy with Gupta's early this year.

Corporate/Professional: 


On the First week of February, I left Job at Best Roadways Ltd, then searched for Jobs in Delhi and struggled.

I worked with e-Fleet Systems Pvt Ltd for some days on march.

On the last week of May I went to my birthplace, Nepal for a week and returned on starting of June.

I worked with Indian Computer Institute till mid July.

Then I came to Chandigarh and started with Scorpion Express Pvt Ltd.

Personal/Educational: 

I have Exams of DOEACC on mid January.

On  April and May I had my Exams on Graduation, So I was at home. During this period Results of DOEACC  Declared and I have passed both Exams that I have taken part earlier.

Got chance to practice with MS-Office from base level at Indian Computer Institute.

Have to leave study at DICS, Punjabi Bagh for some reasons [Reasons can be fetched from Above.]

I joined SLR Infotech, Chandigarh for .Net on the last week of November. Which will be continue till next Quarter of 2012.

I have lost so many things on last year but I remember one thing. One of Friend who is Senior and Founder of a company has told me that- "John, You are so Lucky, You got the Chance to see the truth in the earlier age of your life. These peoples are so cheap and we can't be."

Hope you had fantastic and very nice year. Your trip must be very successful and pleasant. If not don't be afraid or neither loose Hope, You will rock ahead......

John Bhatt
(P.Yar.B Complex)

Reactions: 

Creating Two New Projects...

I am currently busy with my classes.

On my rest time I am currently busy with Two Websites. One of these two is of School and another is personal Blog. Links of these both Websites will be public on next post. And I will let you to have look at my these Works.

Needs your suggestion and feedback for Improvement.

--John Bhatt

Reactions: 
At Chandigarh, India