Introduction to C programming

Here we are going to get introduction to C programming in a practical manner.

introduction to c programming
Photo by Fabian Grohs on Unsplash


A program is a set of instruction given to a computer to solve a problem.To start programming, the first thing we need to know, is the problem. The next step is to brainstorm the problem and find an algorithm which can solve that problem.An algorithm is a sequence of steps followed to solve a problem. A good algorithms has some features like-
  • It is short, simple and unique.
  • It has a output for every possible legal inputs.
  • It can handle any exception if arises in a program.

Now getting towards the topic introduction to C programming

We need to know the basic syntax of C programming which is as follows-
Syntax:
Here,


  • Documentation section is very similar to multiple line comments, everything written between /*...*/ is ignored by the compiler.
  • Preprocessor Directive in C are special program which process our codes before compilation is done.
  • main() function is a very essential part of every program. In C, the program execution begins from the main() function.
  • body of programs includes the steps we perform to solve a problem

       
 Example:


program to add two numbers

Output of above program is 33.
In the above program we can see,


  • How we can write useful information in Documentation Section
  • In above program there is no global variable, all three variables num1, num2 and sum are variable of main() function
  • printf() is used to print the output on screen
  • %d within " " tells the compiler to print the variable sum in format of integer number.

Algorithm to find lcm of two numbers

1. Start.

2. Read num1 and num2.

3. Calculate gcd of the numbers.
Refer  Find gcd

4. LCM=(num1 * num2)/GCD(num1 , num2)

5. Print LCM

6. End.

Euclid's algorithm to find hcf or gcd of two numbers.

1. Start.

2. Read num1 and num2.

3. If num1 < num2,
      Swap values of num1 and num2
       Refer : Swap using third variable
             or, Swap without using third variable

4. While (num1 % num2) != 0 
           num1 = num2;
           num2 = num1 % num2;

5. num2 is the gcd.

6. End.