C Documentation

Introduction

Computer:Computer is an electronics device that can perform various arithmetic and logical operations. It can receive data, process it and produce output. It can store large amount of data.

Block Diagram of a Computer

Functional Units of Digital Computer

A digital computer is considered to be a calculating device that can perform arithmetic operations at enormous speed.

  1. Input Unit:The commonly used input devices are mouse, mike, key board,scanner, optical mark reader, joy stick etc. Thus, we can conclude that, all the input devices accepts the data and instruction from outside world, convert it to a form that the computer can understand, supply the converted data to the computer system for further processing.
  2. Storage Unit:The storage unit of a computer holds data and instructions that are entered through the input unit, before they are processed. It stores programs, data as well as intermediate results and results for output. Its main function is to store information.
  3. Central Processing Unit (CPU):The control unit and arithmetic logic unit of computer are together known as central processing unit (CPU). The CPU is like brain and performs following functions: It performs all calculations, it takes all decisions, and it controls all units of a computer.
  4. Output Unit:An output unit performs the reverse operation of that of an input unit so it supplies information obtained from processing to outside world. Units called output interfaces accomplish this task. Example: monitor,printer,speaker,projector etc.

Difference of Low Level and High Level Language:

Low Level Language High Level Language
They are faster than high level language. They are comparatively slower.
Low level languages are memory efficient. High level languages are not memory efficient.
No need of translator except assembler for AL. Compiler & Interpreter is needed to convert HLL.
Ex: Machine/Assembly Language Ex: C, C++, Java

Operating System

Algorithm & Characteristics of Algorithm

Properties of the algorithm

Advantage & Disadvantages

Advantages of algorithm

Disadvantages of algorithm

Example of Algorithm

           step:-1  Start
           step:-2  input a and b
           step:-3  c=a+b
           step:-4  print c
           step:-5  Stop
           

Flowcharts and its Notations

Flowchart:-It is a diagrammatic representation of sequence of logical steps of a program. Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and process/data flow.

Advantages of flowchart:

Disadvantages of flowchart:

Symbol Symbol Name Purpose
Start/Stop Used at the beginning and end of the algorithm to show start and end of the program.
Process Indicates processes like mathematical operations.
Input/Output Used for denoting program inputs and outputs.
Decision Stands for decision statements in a program, where answer is usually Yes or No.
Connector use to connect the flow of two of more flow charts
Arrow Shows relationships between different shapes.

Example of Flowchart:-

Flowchart of Simple Interest

Pseudo Code


Pseudocode is an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. It is used for creating an outline or a rough draft of a program. Pseudocode summarizes a program’s flow, but excludes underlying details. System designers write pseudocode to ensure that programmers understand a software projects requirements and align code accordingly.

Advantages of Pseudo Code

  1. Pseudocode is understood by the programmers of all types.
  2. It enables the programmer to concentrate only on the algorithm part of the code development.
  3. It cannot be compiled into an executable program.

Example:-

Average of 10 numbers:-

                    Set total = 0
                    Set I = 0
                    While i is less than or equal to 10
                           Input the next number
                           Add the number into the total
                           I=I+1
                    Set the average to the total divided by 10
                    Print the average
                

Structure of C Program

/ Sample of C Program(documentation Section)

#include <stdio.h> // link section

#include<conio.h> // link section

#define pi 3.14 // definition section

int a=10; // global variable declaration

void disp(); // global function declaration

void main() // main function definition

{

float area,r;

printf(“enter radius”);

scanf(“%f”,&r);

area=pi*r*r;

printf(“area=%f”,area);

disp();

getch();

}
     

Characteristics of C

Application of C

Data Types

Data types determine the types of value and the range of values that can be stored in a variable

C support three classes of data types

  1. Primary data type🡪 char, int, float.
  2. Derived data type🡪 array, pointer.
  3. User defined data type 🡪 structure, union, enum.

Program of sum of three number:-

                #include <stdio.h>
                    void main ()
                    {
                    int a, b, c, d;
                    printf("Enter three numbers a, b & c: ");
                    scanf("%d %d %d", &a, &b, &c);
                    d = a + b + c;
                    printf("Sum = %d", d);
                    }
                    
                    OUTPUT
                    
                    Enter three numbers a, b & c : 1 2 3 
                    Sum = 6
            

Diagram of if else program

If Else

The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t.
But what if we want to do something else if the condition is false. Here comes the C else statement.
else is optional statement.
We can use the else statement with if statement to execute a block of code when the condition is false.

Program of even or odd

                    #include<stdio.h>
                        int main()
                        {
                        int n;
                        printf("enter the no");
                        scanf("%d",&n);
                        if(n%2==0)
                        printf("%d is even number",n);
                        else
                        printf("%d is odd number",n);
                        return 0;
                        }
                

Switch Statement

It is a in built multiway decision system in C.
The control statement that allows us to make a decision from the number of choices is called the switch case statement.

Rules for switch statement

Syntax of switch statement:-

                    switch(integer exp)
                    {
                    case value1:
                    block 1;
                    break;
                    case value2:
                    block 2;
                    break;
                    case value n:
                    block n;
                    break;
                    default:
                    block x;
                    }
                

Flowchart of switch statement

Program of Calculator:-

                    #include <stdio.h >
                        int main()
                        {
                        int a,b,c,ch;
                        printf("Enter First number:\n");
                        scanf("%d",&a);
                        printf("Enter second number:\n");
                        scanf("%d",&b);
                        printf("\nEnter 1 for addition:\n ");
                        printf("Enter 2 for subtraction:\n ");
                        printf("Enter 3 for multiply:\n");
                        printf("Enter 4 for division:\n ");
                        scanf("%d",&ch);
                        switch(ch)
                        {
                        default: printf("wrong input\n");
                        case 1 : c=a+b;
                        printf(“sum is :%d\n",c);
                        break;
                        case 2 : c=a-b;
                        printf("Sub is : %d\n",c);
                        break;
                        case 3 : c=a*b;
                        printf(“Mul is%d\n",c);
                        break;
                        case 4 : c=a/b;
                        printf("div is : %d\n",result);
                        break;
                        }
                        return 0;
                        }
                

Loops

The instructions which are used to repeat any statement multiple number of times depending on specific condition is known as repetition or looping control instructions.

Types of loops:-

For loop

It is used to repeat the block of code, on basis of some specific condition.

Syntax

                       (1)             (2)        (3)
                for(initialization ; condition ; increment/decrement) 
                {
                true block statement;  (4)
                }
                statement x: (5)
                

Order of execution:-


T T F 1 2 4 3 2 4 3 2 5

Program of print character 10 times:-

                int i;
                for(i=1 ; i<=10 ; i=i+1)
                {
                printf("a");
                }

               Output:-
                 aaaaaaaaaa
                

While loop

It is used to repeat the block of code, on basis of some specific condition.

Syntax

                    initialization (1)
                    while(condition) (2)
                   {
                   true block statement; (4)
                   increment/decrement; (3)
                   }
                   statement x: (5)

                   Order of Execution:-

                      T      T    F
                      1 2 4 3 2 4 3 2 5
                

Program of print character 10 times:-

                    int i=1;
                    while(i<=10)
                    {
                    printf("a");
                    i = i + 1;
                    }
                    
                    Output:-

                    aaaaaaaaaa
                
                

Do while loop

In do while the block is executed first & then the condition is checked.

Syntax:-

                    Initialization  (1)
                    do
                    {
                    true block statement;  (4)
                    increment/decrement;  (3)
                    }
                    while(condition)  (2);
                    statement x:   (5)

                    Order of Execution:-

                    T       F
                    1 4 3 2 4 3 2 5