Thursday, December 12, 2013

The day when I started learning C language

      It was my 2nd semester at Thadomal Shahani Engineering College when we were introduced to a subject called SPA(i.e. C Programming). I always wanted to learn to code something and make some useful program out of it, so during my 2nd semester I was excited to learn C language. The college started and we were having lectures and practicals to develop our C Programming language skill. At the beginning we were taught how to think logically to develop a program and also how to write an algorithm and make a flowchart so later we can code in C language using that logic.

      I used to pay attention to this kind of subjects, because these were the subjects which I like the most. At the start it was difficult for me to write algorithm and draw a flowchart, as the days passed I managed to write a proper algorithm and it was my first step to learn programming. Also, we were taught the basic steps and syntax which was required to start coding in C language. During every practical hours, we were given a problem statement and we were told to solve it on our own. At the start I used to face problems in the practical and I had spent even 2-3 hours thinking about how to write even a simple Fibonacci program which will take a limit from the user and print Fibonacci numbers till that limit.

      As the days passed, I got the hang of it and started coding all by myself. It was strange but I always used to code first and then write the algorithm on that code, maybe because I used to think of the logic in my mind and after that start to code instead of writing an algorithm.

      For all C enthusiastic, let me give you a tip on how to solve any pattern given to you.
 Lets analyse this triangle.

  1. It is a star pattern, so print statement will require "*" in it.
  2. Here 3 triangles are there and we have to print spaces in between.
  3. Four loops would be required. One for different lines and one for each triangle.
  4. So, one outer loop would be required with three inner loops.
  5. As line number increases, number of stars in 1st and in 3rd triangle will decrease,One thing you should realize that number of spaces at each line increases by 2 i.e twice the number of line. 
  6. So the loop goes as follows.
  for(i=0;i<n;i++)                //Outer Loop
    for(j=0;j<n-i;j++)            //Runs for n-i times to print star
      printf("*");                    //1st Inner Loop
    for(k=0;k<(2*i);k++)    //Runs for 2*i times to print spaces
      printf(" ");                   //2nd Inner Loop
    for(m=0;m<n-i;m++)   //Runs for n-i times to print star
      printf("*");                  //3rd Inner Loop
    printf("\n");                  //To move to next line

      Lastly, I would like to thank my SPA (i.e. C Programming Language) subject teacher for all the help and support I needed and would like to dedicate this quote to her.