*

*

Data type in C

Thursday, May 29, 2014

C is a data type enriched language.There have opportunity to work with different data types in C programming,like 5,2.03,a.....z,A.....Z,#,$,~,% etc.Compiler allocates memory space in accordance with data type.ANSI C support four data types:
  1. Primary or fundamental data type,
  2. User defined data type,
  3. Derived data type and
  4. Empty data set
 
Fig.:Data type.
But universally  C has five basic data type:

 
Fig.:Basic data type.






Hello world program

Wednesday, May 28, 2014

How to display a message in c program.


#include<stdio.h>
#include<conio.h>
void main ()
{
    clrscr();
    printf("This is my first program");
    getch();
}

Example of algorithm and flowchart

Algorithm and flowchart for adding two numbers.

Fig.:Algorithm and flowchart.

Algorithm and flow chart

Algorithm:

               Every work is the combination of some small portions.By doing these we can complete the total work.Similarly,to solve a problem by programming,at first possible ways should be found out.Then,dividing these whole purposes into small parts it should be done.Solving of a problem by doing it in small parts and combing into whole with logical fashion is known as algorithm.

Flowchart:

               Graphical representation of logical algorithm is called flowchart.A flowchart is consists of different figures.Flowchart is important for program writing and analysis.

It can be two types:
  1. Program flowchart
  2. System flowchart

Program flowchart and it's symbol:

  • Terminal symbol:  
                  Oval shaped symbol which indicate start and end.Start and End are written into the oval.
Fig.:Terminal symbol.

  • Input/Output symbol:
                 A parallelogram shaped symbol is used as to indicate data inputting and outputting.
Fig.:Input/Output symbol.
  • Process symbol:
                 Process is indicated by rectangle.In area main subject is described.
Fig.:Process symbol.
  • Decision symbol:
                 Diamond shaped symbol is used to compare and making decision.There are two decision yes and no is taken accordance to the process.

Fig.:Decision symbol.
  • Flow symbol:
                 Process symbol with direction is used as flow symbol.
Fig.:Flow symbol.
  • Connector symbol:
                
Fig.:Connector symbol.
  •  Loop symbol:
 
Fig,:Loop symbol.
  •  Subprogram:
  
Fig.:Subprogram symbol.
           

Process of program planning

Wednesday, May 14, 2014

The main objective of programming is to solve problems.So,before starting program coding you have to understand the problem which has to solve and then analyze the possible options for solution.There is no alternative of program planning for standard and efficient programming.For a proper program planning following steps are essential:
  1. Problem analysis
  2. Algorithm and flow chart development
  3. Program coding
  4. Program compilation
  5. Program testing and debugging
  6. Program execution
  7. Program documentation
  8. Program maintenance.

Problem analysis:

               First step of  programming is problem analysis.You have to understand the problem,data required or used in problem solving.Then select the programming method such as-modular programming,structured programming,top-down or top-up programming etc.Method selection depends upon the problem under consideration.Where results will be stored or shown has to select.File,printer,monitor may be the possible option for storing or displaying results.So,understand the problem in details is the first step of program planning.

Algorithm and flow chart:

               Algorithm and flow chart should be prepared before writing code.Time required for giving output from the program depends upon the algorithm.Programming statements are arranged in algorithm step by step.As a result program can be written in any language.Beside algorithm development,flow chart also important for programming.Flow chart is prepared by using different symbol and figure.Mainly a complex program is simplified by developing algorithm and making flow chart.

Program coding:

               There have different language for program coding.Which one will be used it depends upon the problem,programer knowledge,requirement,accuracy etc.So,according to these should select a programming  language.Program coding is define as to convert algorithm and flow chart statements into programming language.

 Program compilation:

               Compilation means transformation.Programs are usually written in different types of programming,computer is not able to understand these program.Computer only can understand machine language.So we have to transform programming language into machine language.For doing this a software named compiler is used to convert programming language to machine language.First compiler read the source code and convert  to machine code and include necessary help file and show the result.After that converted machine code can be opened from operating system without any help file or software.

Program testing and debugging:

                There may have different errors like typing error,syntax error, logical error etc. in the written program.This errors in the program is called bug.Correction of this errors is called debugging.Errors should be corrected  before compilation.If there remain any error in program,it will be detected in compilation.It should be noted that a correct program can lead to the right result.

Program execution:

               For  executing or showing right result it requires to give proper instruction after compilation.It is needed to link some file to execute the program.Executable file is prepared by compiling and linking required file.Executable file gives the output in accordance to input.

Program documentation: 

                In program documentation,it contains the description about the program.Main problem,algorithm,flow chart,brief description,table,relevant data and assumed result are noted in documentation.Also some techniques,frequently occurring problems and their solutions are include in this section.It's like manual to the user or for the programmer himself.

Program maintenance:

               It may be required to change the program for hardware change or any other reason.Program changing,extension,reduction are included to program maintenance.

Fundamentals of C Programming

Introduction:

              C is one of most used and liked programming language in the world.Most of the programmer like it for programming.From different perspective of programming such as-program coding,
compilation,application and utilization etc.,C language is specialized compared to the other language. Even making some development C language is now converted to object oriented programming language C++.
C is such a programming language that one can be a skilled programmer by practicing it regularly.

 

Some Basics:

               For the novice programmer some essential topics are included in as follows which will help to understand the programming:

Program:

               An appropriate set of instructions which can solve the definite problem and give a desired output is called program.
Given instructions are stored in computer memory and these can be executed anytime.For execution of  program following tasks should be done:
-A set of instruction should input to the computer memory by means of input device such as key board,pen drive etc. 
-Input data should be processed by the processor for desired output.
-Output data need to display by output device like monitor,printer etc.
Fig.1: Input output system.

Terminal:

               All input-output device like-keyboard,scanner,monitor,printer,plotter etc.are called terminal.

Machine language:

               Computer system only can understand machine language that means 0 and 1.Writing machine language is hard and bothersome.
                             -Program coding is very difficult,
                             -Time consuming,
Though writing machine language have some difficulties but it is more efficient.

Programming language:

               The limitation of machine language is removed by developing programing language.On the other hand  the efficiency of program and machine remain excellent.Traditional English,Chinese, Malay,are not the programming  language.Creating environment for writing program,linking associate file with main file,debugging,translation,execution,saving,closing and opening file are operated sequentially.

Translator:

               Programming language is translated to machine language or 0 and 1 through translator.It is mainly a programming software.There are different types of translator.
  1. Assembler
  2. Interpreter
  3. Compiler

Hardware and Software:  

               Computer parts like- mouse,keyboard,monitor,microprocessor etc. are called hardware.On
the other hand program,programming language,operating system,translator which are required for the operation of hardware are called software.

 

Types of programming language:

Programming languages can be classified into three types:
  1. Low level language
  2. Mid level language
  3. High level language
Low level language:
               In this type of language some mnemonics like ADD,SUB,MOV,LOAD etc. are used instead of binary code 0 and 1.Assembly language is the example of low level language.Assembly language is translated into machine language through assembler.
High level language:
               High level language is not based on symbol or symbolic word.It is like English language.
To use this language it is not required to learn the internal structure of the computer in detail.Ada Modula-2,Pascal,COBOL,FORTRAN,BASIC these are some high level language.Interpreter or compiler is used to translate this high level language into machine language.
Mid level language:
               C/C++,FORTH,Macro-assembly language etc. are the examples of mid level language which has the properties of both high and low level language.

Special features of C programming:  

1.A mid level language:  
               C is called mid level language  because it support some feature of high level language and also some of low level language.

2.A structured language:
                C language is a combination of small function or module that’s why it is easy to test,debug,maintain and execution.

3.A portable language:
               C code is extremely portable that means all computer support C program.As for example a C program written in Apple computer can easily transfer to the IBM PC.

4.A general purpose language:
               C is called general purpose language because it is effective for all kind of purposes.

5.Not a typed language:
               All though C has five basic built in data type but it not a typed language like
Pascal or Ada.

Basic Structure of C program:

               The basic structure or format of C program is consists with a main function with one or more function.There are required statements in function or sub-routine to perform specific task.General format of C program is shown below:
Fig.2:Basic structure of c program.
Documentation section:
               Some comments line or comment statements are stated in this section,these lines has no effect on execution of the program.But these will help to know about the program name,program related information.Two forward slash (//) is used for single line commenting and /* and */ are used as starting and ending respectively for many line commenting in C.

Link section:
               Some header files are linked by #include directives.Compiler treat these files as a part of main file due to link.Compiler copy necessary data from library function or built in function during compilation.Linking is must for program execution.The format of linking is  #include<header file name>
 Example:  #include<stdio.h>
  
Definition section:
               All symbolic constants are described by #define directives.
 Example: #define pie 3.1416

Global declaration section:
              Variables used in many function are called global variable.Global variables are declared in above of all function.

Main function:
               A main()  function is must has to be in C program.There are two part in main function,declaration part and executable part.Variables used in executable part are declared in declaration part.At least one statement is must needed in executable part.A semicolon (;) must have to use in main function after each statement.In main function all statements are written between { }.

Subprogram:
               This program are usually known as user defined function.This functions are called from main function.These function can be written above or below the main function.User defined function is used to make easier and understand the program.