Tuesday 14 August 2012

Input-Output Functions in C


Input-Output Functions in C



The Two Types of  C Functions

1) Predefined / Built-in/ Library Functions 
           These are defined in Header Files (.h)
     1.1) Mathematical   : sqrt() , abs(), floor(), ceil(), sin(), cos(), tan()
     1.2) Numeric Input  : scanf()
     1.3) Numeric Output  : printf()
     1.4) char Input    : getc(), getchar(), getch(), getche() & scanf()
     1.5) char output   : putc(), putchar(), printf()
     1.6) String Input   : gets(), scanf()
     1.7) String output  : puts(), printf()
     1.8) String manipulation : strlen(), strupr, strlwr(), strcpy(), strcat(), strcmp().....
     1.9) Screen clearing : clrscr()
     1.10) String Conversion      : atoi(),  atol()  , atof() - <stdlib.h>
           etc.........
2) User-defined  Functions
    2.1) main()  : Mandatory Function - Automatically called by Compiler
    2.2) sub-functions : optional
           - declaration
           - definition
           - calling / invoking

Operators in C

Operators in C

Operators are basically Symbols that perform some operation on Data.

Types of Operators in C

1. Binary Operator

2. Unary Operator

1. Binary Operators Classification :
   a)  Arithmetic Operators ( +  -  *    /  % )

   b)  Relational Operators  ( ==   >   <   >=   <=  != )

   c)  Logical Operators  ( &&  ||   !  )

   d) Assignment Operators / Short Hand Operator ( =     +=    -=    *=     /=     %=  )

   e) Bit-wise Operators  ( &   |   ~   ^  )

2. Unary Operators Classification 
   a) Increment Operators  ( ++ )
         1 ) Pre Increment Operator 
         2) Post Increment Operator 
  b) Decrement Operator ( -- )
         1 ) Pre  Decrement  Operator
         2) Post  Decrement Operator 
 c) Unary Minus Operator  ( - )
 d) Special Operators  
        1) sizeof Operator
        2) Address Operator ( & )
        3) Pointer Operator ( * )
        4) Scope resolution Operator ( :: )
        5) Separator ( , )
   


Short Hand Operator  or Arithmetic Assignment Operators

  a += 100 meaning is  a = a+100
 a *= 100 meaning is  a = a*100
 a /= 100 meaning is   a = a/100
 a -= 100 meaning is  a = a-100

 The Rule of  = in expression
No expressions are allowed in right hand side of  =

 a= 10
 b= 20;
 a+b = c;     //  Error




Monday 13 August 2012

C Programming Constructs


C Programming Constructs

In C Programming, we are using three important programming constructs.
1 .Variables
2. Expression
3. Data Types

Data Type :
          Data Type indicates the kind of Data.
Data Type are classified as two types.
1. Primitive
2. Derived

3 Basic - Primitive Types

     Type   - Memory in Byte - Range
1)  char    -            1            -128 to +127
2)  int       -            2            -32678 to +32767
3)  float    -            4            2 billion values

Derived Data Types
1. short int
2. long int
3. double
4. long double

Qualifiers
1.signed
2. unsigned


Variable :
In C Program, if you want to handle the data , you should store them temporarily in memory. For that, we have to use variable.
Variables are names used to assign some value temporarily in memory.
Technically, variables are named memory location used to store temporarily one data at a time.
To use the variable, first we have to declare them.

Syntax for variable Declaration :

 data_type variable_name [ = some value ] ;

Rules for variable Names
1. No Keyword
2. No number as a 1st Character
3. No blank space
4. No Special characters such as + - * / & @ etc...
5. may be short and meaningful.



Examples :


int char;   /* Invalid declaration  - No keyword*/
char 1A; /* Invalid declaration  - No number as a 1st Character*/
char A, B; /* valid declaration */
int  a,b,cd; /* valid declaration */
int A B; /* Invalid declaration  - No Blank space*/
int A, B=20; /* valid declaration */
int a+b; /* Invalid declaration  - Special char not allowed*/



Constant 
         The constant is like variable, The named Memory locations - used to store values. But  the values 
can not be modifiable.

1. Symbolic Constant : 
           Declared outside of all function - on the top of the program using #define 
                 #define pi 3.18

2. Constant  :  
          Declared  inside  the main() or inside any user defined functions
                 const float pi = 3.18 ;




Expression :
The combination of data and operators.
Ex. :  a+b
         a==b
        a >b

Sunday 12 August 2012

Getting Start with C


Getting Start with C 

History of C Programming Language


C Language is designed by Dennis Ritchie at Bell Laboratories in the early 1970s.
C Language  is Influenced by various early Languages like ALGOL 60 , CPL , BCPL , B.
The Language B is interpreter-based. 
Interpreter is a translator program that convert one line at a time. 
Hence B language programs were slow during translation into machine coding.
Dennis Ritchie modified B language and made it as compiler-based.
Compiler is a translator program that convert entire file at a time. 
The modified compiler-based B language is named as C.

What is C?


C is a Programming Language:
        Possesses powerful low-level features of 2 G Languages.
        Provides loops and constructs of 3 G Languages.
       Is very powerful and flexible - Procedure Oriented Programming Language.

C Features
Key features that made C as a widely-used language
1. Pointer
       Allows to refer the memory location - using address Operator & and Pointer Operator *
2. Memory Allocation
       Allows static as well as dynamic memory allocation ( using malloc() ) .
3. Recursion
       It is a  functions in which a functions calls itself.  Example - Factorial.  n ! = n * (n-1) !
4. Bit Manipulation  
       Allows manipulation of data in its lowest form of storage such as 0 & 1.



C is case-sensitive programming Language.

The General Structure of C Program:

Pre-process Directive

sub function declarations ;

void main()
{

    /*  main Function statement */
     /* Sub_function calling Statements */
  .............................
}

 sub_function definition
{
.............................
}


Once you create a program, the program has to be saved with .C file extension.
Depends on your compiler and Operating System, you may also use different  file extension.

Various Compiler Programs are used to work with C, like
  1.    Borland Turbo C
  2.    gcc
  3.    Micro Soft C


Working with Turbo C++ Version 3.0

To create and compile the C Programs using Turbo C++ ver 3.0

This Compiler comes with Editor Program called as IDE ( Integrated Development Environment)
Hence you can type , save, compile, edit and Run the Program in one program window

1. From windows, move to the Command Prompt (cmd)
2. If the Turbo C is installed in C:\TC\BIN path,
   Type the following DOC commands in Command Prompt :
   1. cls - to clear dos screen
   2. cd\ - to move the Root Drive
   3. cd   tc\bin - to move to Tc\Bin directory ( Turbo C Installation directory )
   4. tc - to open the Turbo C Compiler - Editor
       Turbo C - window has opened.

Within Turbo C,  create and save the "C' File as follow :
File -> New  : To create a New File 
File -> Save  : To Save the File into Harddisk Drive
    Type the File Name along with Path ( Drive & Folder )
     c:\prog\p1.c
Type the Program
Again save the file. File->Save.
Compile -> Compile  : To Compile the Program
If no Errors, Run-> Run : To Execute the Program
Window ->Output  : To view the output message.
Window ->Close : To Close the current Window.

If Error is displayed, then press enter key and Read the Error message.
Press the Enterkey to point the Error and Clear the Error.
Save , Re-Compile and Execute the Program..

The General Program Structure

/* Comments – Program Heading */
#include <Header Files>
Global variable declaration ;
FunctionReturnType main()
{
   variable declaration Statements ;
   Screen Clear Function calling ;
 Initialization ;
 Assignment ;
 Input Statements ;
   Control / Decision Making Statements
   Output statements ;
   function calling Statements ;
   Return Statements ;
}




Algorithm and Flowchart


Algorithm and Flowchart 

What is Algorithm?
      The simple step by step non-formatted  statements to solve the specific problem .

Characteristics for good Algorithm: 
   The set of well-defined clear statements
   An algorithm should have zero or more input. 
   An algorithm should exhibit at least one output. 
   An algorithm should be finite.
   Each instruction used in an algorithm should be basic and easy to perform.
   An algorithm can be represented diagrammatically in the form of a flow chart.

Template of Algorithm

Step 1 - START
It represents beginning of the algorithm.
Step 2 - DECLARE
The variables used in algorithm are declared.
Step 3 - INPUT
Input the values
Step 4 - Assignment or Process or Looping or Mathematical Expressions 
The required result is generated.
Step 5 - OUTPUT
It displays the output or result.
Step 6 - STOP
It is an end of Algorithm    


Example for Algorithm

Problem : 
             Convert any Decimal number to Binary format


Step 1 : Start the process
Step 2 : Declare the x as integer Number.
Step 3 : Get the decimal number as x.
Step 4 : Divide x by 2; Assign quotient as x and Keep the remainder.
Step 5 : Repeat step 4 on the quotient x; 
              Repeat step 4 until the quotient x becomes one.
Step 6 : Write all remainder digits in the reverse order (last remainder first – left Most digit) to form the final result.
Step 7 : Display the result 
Step 8 : Stop the Process

Flowchart 


Flowchart 

The Pictorial representation of Algorithm is called as Flowchart. 
A graphical representation of a process (e.g. an algorithm), in which graphic objects are used to indicate the steps & decisions that are taken as the process moves along from start to finish.

The Symbols of Flowchart


Example for Flowchart :
Problem :   Convert temperature from Fahrenheit to Celsius






Introduction to Programming



Programming is the method of writing the Program.

Software
Software is a Set of Programs. 
It is used to give the solution for the Business organization like to automate the Business Process,
providing better service to customer and helps in Decision Making Process.




Programs are created using Programming Languages,

I.  Programming Languages Types 
             Used to develop the Programs

1. LLL ( Low Level Language ) : 
           The characters such as 0, 1  used to write the program.
           Computer can easily understand.

2. ALL ( Assembly  Level Language ) : 
            The characters such as 0, 1 and mnemonic codes ( such as ADD, SUB, MUL, DIV)  are used to write the program.
          Computer can not understand mnemonic codes. 
          Requires Assembler to convert the Assembly Program into LLL program.

3.  HLL ( High Level Language )
 The English alphabet characters and numbers are  used to write the program. Program statements are like the English statement. 
 Human can easily understand. 
Computer can not understand . Hence requires Translator (Compiler, Interpreter ) to convert the High Level Language Program into LLL program. 
Two main types of High level Languages 
1. POP  (Procedure Oriented  Programming )
        Data and functions are separate. 
        Program consist of set of Functions or procedures.
        Example :   Pascal, C, 

2.  OOP (Object Oriented Programming) : 
         Data and functions are combined into single unit - called class.
         Program consist of set of Functions or procedures.
         Example :   C++, C# , Java, LISP

 II. Markup Languages Types 

            Used To develop the Web Pages
    
Types of  Markup Languages
SGML ( Standard Generalized Markup Language)
 HTML  ( Hyper Text Markup Language)
 XML    (extensible Markup Language)
 DHTML  ( Dynamic HTML )

  III. Modeling Language 

             Used to create the designs.

  UML (Unified Modeling Language) 

Introduction to Problem Solving using Computer


Problem Solving using Computer 

What is Problem ?
Problem is any state which requires some sort of solution.

Some of the Business Problems:

1. Business organization wants to maintain their customer’s data in simple, cheaper & secure manner.
2. Business organization wants to provide better service to their customers like providing Quick, accurate and detail Billing, sending offers, displaying Products with details.
3. Business organization wants to provide better remote service etc…..

Computer software is used to solve various Business problems.

Generally, many of the business problems can be solved with the help of computer software.
Hence, Software is treated as Business Solution. Basically Software is Collection of Programs.
Program is set of Instructions written in some Programming Language.
Hence, to develop software, we have to write programs.

To write the Program, we have to learn Programming Language.

Programming Language provides  Syntax & Semantics(Rules and Regulations) to write the Program.

Hence if we want to develop software, i.e. to write program, we should learn Programming Language.



Problem Solving methods :
1. Study the Problem
2. Develop the simple solution ( create some idea to solve the problem).
    write them in step by step statements - Algorithm
3.  Develop the pictorial representation of solution - Flowchart
     Flowchart used to ensure the proper flow of Data within the process.

4. Apply the Programming Language Syntax and semantics for Algorithm and Flowchart.
 Develop the solution in Formal Statements as per Programming Language Syntax and semantics-  Program.

Software Development Life Cycle Phases - Process : 
1. Analysis
2. Design 
3. Coding  - Program coding is developed in this phase.. 
4. Testing 
5. Implementation 
6. Maintenance 

  Collecting the Problem and Analyse the Problem - Problem Study
  The step by step statements to solve the Problem - Algorithm 
  Pictorial representation of the Algorithm- Flowchart 
  Formal statements as per Programming Language  - Program

Program 
    The set of sequence of formatted Instructions to solve the problem with the help of computer.