Monday 9 January 2017

I/O Functions

           

                         Classification:


Header Files:
-Generally all the programs accept some input from keyboard,process it,prepare some output and print it on the screen.
-The application programming interface (API) of the C standard library is declared in a number of header files. Each header file contains one or more function declarations, data type definitions, and macros.
-C is the functional language provides readymade function.
-A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.
-When we want to  use them,we must include that file using include statement.The syantax of that statement is given below.

#include<header file name>

A) Scanf-function is used to read values using key board.It is used for runtime assignment of variables.
-The General form of Scanf( ) is
 scanf("formating String",list_of_adderesses_of_variables );

-The format string contains
 scanf("%d %f %c",&a &b, &c)

The control string characters 

1.White spacce characters (space,\t,\n,\v,\r,\f)
2.Conversion characters (d,c,i%.,o,u,s,e,f,g,x,[..])

B) printf( ); function is used to print/display values of variable using monitor:
     
-The General form of print( ) is
  printf("control String",list_of_Variables );

-Escape sequences that begin with a '\' sign
-Conversion specification that begin with a% sign
-Characters that are simply printed as they are

Eg:Program

     void main( )
{
int avg=250
float per = 70.2;
printf("Averarge =%d \n percentage=%f'",avg,per);
}

Output:
Average =250
Perecentage =70.200000

printf( )examines the format string from left to right and prints all the characters until it encounter a'%' or '\' on the screen.When it finds %(Conversion Specifier) it picks up the first value.when it finds '\' (escape sequence) it takes appropriate acion (\n-new line).This process continues till the end of format string is reached.

Eg:Program

   void main( )
{
float per;
printf("Enter values for avg & per");
scanf("%d %f',& avg & per);
printf("Average=%d\n Percentage=%f ",avg.per);
scanf("%d %f ",& avg& per);
}

Output:
Enter values for avg & per 250  70.2
Average =250
Percentage = 70.200000


Unformatted functions character I/O functions

getchar ( ) -function is used to read one character at a time from the key board.

Syntax ch =getchar ( ); where ch is a  char Var.

void main ( )
{
char ch;
printf("Enter a char");
ch = getchar ( );
printf("ch=5c",ch);
}

Output:
Enter a char D
D
ch=D

-when this function is executed,the computer wil wait for a key to be pressed and assigns the value to  the variable when the "enter" key pressed.

putchar ( );    Function is used to display one characters at a time on the monitor.

Syantax:    putchar (ch);
Ex char ch ='D'
putchar (ch);

-The Computer display the value char of variable 'ch' i.e D on the Screen.

getche( );   function is used to read a char from the key board without expecting the enter key to  be pressed.the char read wil be displayed on the monitor.

Syntax; ch=getche( );

getch ( );    function is used to read a char from key board and does not expect the "enter" key press.

Syntax; ch=getch( );

-when this function is executed ,computer waits for a key to be pressed form the dey board.As soon as a key is pressed,the control is transferred to the nextline of the program and the value is assigned to the char variable.It is noted that the char pressed will not be display on the screen.























Saturday 7 January 2017

Introduction to Computer & Programming

Introduction:

-A Computer is divided into 2 categories -softwere and hardwere.
-Hardwere is the physical component and softwere is logical component of the computer.


Computer Languages:

Computer languages  are divided into 2 categories -low level language,and High level language.Low  level language as further divided into 2 types -machine language and assembly language.

(1) Machine Langauage:
-Computer directly understands this language.it is the language of 0's and 1's.Every instruction consists of order,data,address and all are in terms of 0's and 1's,thus it is very difficult to understand as well as remember.

Advantages
-The programs are compact and small.
-Suitable for low voloume application,small simple program where the prototype is the final Product.
-It does not require any extra system program to run.

Disadvantage
-Machine language program are not portable.
-The progarm are slow to enter since you must enter each bit individually.
-The Progarms are long and tiresome to write.
-Progarmmer must have detailed Knowledge of the architecture of particular microprocessor.

(2) Assembly Langauage:
-Every machine language instruction is assigned to english word mnemonic such that it should describe functions of instruction.such language of mnemonics is called as Assembly language.
Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming languages, which are generally portable across multiple systems. Assembly language is converted into executable machine code by a utility program referred to as an assembler like NASM, MASM, etc.

Advantages
-The program are very easy to understand or debug.
-The programs are fast to enter using alphanumeric keys of keyboard.

Disadvantage
-Assembly language programs are not portable.
-It requires assembler and loader for translation.

(3) High level Langauage:
-High level very similar to natural languages.
Example:C,C++,JAVA,.NET

Advantages of high Level language:
-The programs are very easy to understand or dubug.
-The High level instructions are easy sentences so it is very easy to learn.
-The Programs are Portable.

Disadvantage of high Level language:
-High level language programrequires compiler or interpreter to translate high level language Program to machine level that means object code.
-Programmers need to learn structure of high level language programs and syantax of every statement.

(4) Algorithms:

What is the Algorithm ?

-Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem.

Algorithms Properties:

Definiteness:Eash step of algorithm must be clear and un ambiguous.
Effectiveness:Every step must be basis and essential.
Finiteness:Total number of steps used in algorithms should be finite.

Advantages :
-Easy technique to understand logic.
-Easy identifications of the mistakes by non computer person.

Disadvantage :
-Time consuming.
-Big tasks are difficult to put in algoriths.

ShapeNameDescription
Flowchart Line.svgF
l
o
w

L
i
n
e
An arrow coming from one symbol and ending at another symbol represents that control passes to the symbol the arrow points to. The line for the arrow can be solid or dashed. The meaning of the arrow with dashed line may differ from one flowchart to another and can be defined in the legend.
Flowchart Terminal.svgT
e
r
m
i
n
a
l
Represented as circles, ovals, stadiums or rounded (fillet) rectangles. They usually contain the word "Start" or "End", or another phrase signaling the start or end of a process, such as "submit inquiry" or "receive product".
Flowchart Process.svgP
r
o
c
e
s
s
Represented as rectangles. This shape is used to show that something is performed. Examples: "Add 1 to X", "replace identified part", "save changes", etc....
Flowchart Decision.svgD
e
c
i
s
i
o
n

Represented as a diamond (rhombus) showing where a decision is necessary, commonly a Yes/No question or True/False test. The conditional symbol is peculiar in that it has two arrows coming out of it, usually from the bottom point and right point, one corresponding to Yes or True, and one corresponding to No or False. (The arrows should always be labeled.) More than two arrows can be used, but this is normally a clear indicator that a complex decision is being taken, in which case it may need to be broken-down further or replaced with the "predefined process" symbol. Decision can also help in the filtering of data.
Flowchart IO.svgI
n
p
u
t
/
O
u
t
p
u
t
Represented as a parallelogram. Involves receiving data and displaying processed data. Can only move from input to output and not vice versa. Examples: Get X from the user; display X.
Flowchart Annotation.svgA
n
n
o
t
a
t
i
o
n
Annotations represent comments or remarks about the flowchart. Like comments found in high-level programming languages, they have no effect on the interpretation or behavior of the flowchart. Sometimes, the shape consists of a box with dashed (or dotted) lines.
Flowchart Predefined Process.svgP
r
e
d
e
f
i
n
e
d

P
r
o
c
e
s
s
Represented as rectangles with double-struck vertical edges; these are used to show complex processing steps which may be detailed in a separate flowchart. Example: process-files. One subroutine may have multiple distinct entry points or exit flows (see coroutine). If so, these are shown as labeled 'wells' in the rectangle, and control arrows connect to these 'wells'.
Flowchart Preparation.svgP
r
e
p
a
r
a
t
i
o
n
Represented as a hexagon. May also be called initialization. Shows operations which have no effect other than preparing a value for a subsequent conditional or decision step. Alternatively, this shape is used to replace the Decision Shape in the case of conditional looping.
Flowchart Connector.svgO
n
-
P
a
g
e

C
o
n
n
e
c
t
o
r
Generally represented with a circle, showing where multiple control flows converge in a single exit flow. It will have more than one arrow coming into it, but only one going out. In simple cases, one may simply have an arrow point to another arrow instead. These are useful to represent an iterativeprocess (what in Computer Science is called a loop). A loop may, for example, consist of a connector where control first enters, processing steps, a conditional with one arrow exiting the loop, and one going back to the connector. For additional clarity, wherever two lines accidentally cross in the drawing, one of them may be drawn with a small semicircle over the other, showing that no connection is intended.
Off page connector.pngO
f
f
-
P
a
g
e

C
o
n
n
e
c
t
o
r
Represented as a home plate-shaped pentagon. Similar to the on-page connector except allows for placing a connector that connects to another page.

Advantages:
-Easy to draw.
-Easy Technique to understand logic.
-Easy to identify the mistake by non computer person.
-Easy for branching and looping.

Disadvantages:
-Difficult for modification.
-Time consuming.
-Difficult task to draw flow charts for big programs.