Looping in C Programming Language

 Looping in C Programming Language Use: When we want to perform specific task repeatedly then we can use looping. In C Language there are three type of loop: For Loop While Loop Do while Loop Nested for Loop Each Loop statement requires three things: Initialization  Test Condition Increment/Decrement Operation 1. For Loop: For Loop is a repetition control structure which allow us to write a loop that is executed a specific number of time. Syntax:               for( initialization ; test condition; increment/decrement operation)                 {                    ------                    body of for loop;                    ------               } 2. While Loop: While Loop is use to per to p...

Structure of C Program

 STRUCTURE OF C PROGRAM


C Program has following sections:


1.Documentation Section:

    In these section, we can write details about program and programmer. Like - program title, user/student name, roll no, semester etc... These details can we given in comments. Comments can be given in two ways:

        A. Single Line Comment: We can give comment in single line               using //

            Ex. //WAP to find percentage.

        B. Multiple Line Comment: Multiple lines comment can we                  give using /* ------------*/.

            Ex. /* Program title: WAP to find percentage.

                       Student name: Ram

                        semester: 1/A */

2. LINK SECTION: 

  • In this section, we include system libraries or header files. 
  • Source code or definition code of system defined function are written in system libraries.

3. DEFINITION SECTION:

  • In this section, we can define constants.
  • Constants means those variable which have fixed value throughout the program.
  • Example:
  • #define pi 3.14
  • #define size 80          

4. GLOBAL DECLARATION SECTION:

  • In this section, we declare global variables and user defined functions.
  • Global variable are those variables which we can use anywhere in the program
  • User defined function is created by user to perform specific task.
  • Example:
  • void add(); // declaration of user defined function.
  • int a,b,c; // declaration of global variables.        

5. MAIN FUNCTION SECTION:

  • Void main() is a user defined function.
  • Execution of program starts from void main() function.
  • Void main() function starts with { and ends with }.
  • It has two parts:        

                1. Variable Declaration

                2. Executable Part

        1.Variable Declaration: We can declare all variables  in this                    section.

        2.Executable Part: We can write source code of program in                 this section.

            Example:

                            void main()

                            {                            

                                    int a,b,c;           <---- variable declaration

                                    --------          

                                    --------               <-----Executable code

                                    --------

                            }

6. SUB PROGRAM SECTION:

  • In this section, we write definition code of all user defined functions.
  • When program is divided into sub tasks, each task is know as user defined function.       
  • Example:

                Void main()

                {

                        ------

                        -----

                        -----

                }

                void add()

                {

                        -----

                        -----

                }



Comments

Popular posts from this blog

Data Types in C Program

Different Modules to solve the program/problem

Operators in C Program