Sunday, 30 November 2014

Format Specifiers and Escape Sequences


Format Strings and Escape Sequences:-

All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.

List of commonly used format specifiers:


%c – used for single char in C
scanf(“%c”, &ch);
printf(“%c”, ch);


%d – decimal number (whole number)
scanf(“%d”, &num);
printf(“%d”, num);


%e – scientific notation/exponential form
scanf(“%e”, &result);
printf(“%e”, result);


%f – number with floating or decimal point
scanf(“%f”, &pesos);
printf(“%f”, pesos);


%u – unsigned number
scanf(“%u”, &nos);
printf(“%u”, nos);


%x – hexadecimal number
scanf(“%x”, &value);
printf(“%x”, value);


%X – capital number for hexadecimal number
scanf(“%X”, &nos);
printf(“%X”, nos);


%o – octal number
scanf(“%o”, &value);
printf(“%o”, value);


%s – string of characters
scanf(“%s”, str);
printf(“%s”, str);

%% - print a percent sign
scanf(“%%”, &value);
printf(“%%”, value);

List of commonly used escape sequences:

\\ - prints backslash

\’ - prints single quotes

\” - prints double quotes

\? - prints question mark

\n - newline

Associativity of Operators:


i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8

i = 6 / 4 + 4 / 4 + 8 - 2 + 5 / 8 operation: *

i = 1 + 4 / 4 + 8 - 2 + 5 / 8 operation: /

i = 1 + 1+ 8 - 2 + 5 / 8 operation: /

i = 1 + 1 + 8 - 2 + 0 operation: /

i = 2 + 8 - 2 + 0 operation: +

i = 10 - 2 + 0 operation: +

i = 8 + 0 operation : -

i = 8 operation: +

_______________________________________________________________________



kk = 3 / 2 * 4 + 3 / 8 + 3

kk = 1 * 4 + 3 / 8 + 3 operation: /

kk = 4 + 3 / 8 + 3 operation: *

kk = 4 + 0 + 3 operation: /

kk = 4 + 3 operation: +

kk = 7 operation: +

________________________________________________________________________



Writing a Program


Writing Program:-

In order to write program in any programming language, it is necessary to know what about its command and syntax. Programmer must also know that what are the basic usage of commands and other programming structure. Programs written in C language is really not much difficult to understand that one written in any other language, once you become used to the basic syntax.


Function Definition: All C programs are divided into units called ‘functions’.
Every C program consists of one or more functions. Consider the following program:


#include <stdio.h>
void main(void)
{
printf ( "Hello, World");
}


The above program has only one function “main”. This function is one to which control is passed from the operating system when the program is run, i.e. it is the first function executed. The word “void” preceding “main” specifies that the function “main” will not return a value. The second “void” in paranthesis specifies that the function takes no arguments.


Input Statement:-

A statement used to input a single character or a sequence of characters from the keyboard.

1. getch – a function used to input a single character from the keyboard without echoing the character on the monitor.
Syntax: getch( );
Example: ch = getch( );

2. getche – a function used to input a single character from the keyboard, the character pressed echoed on the monitor.
Syntax: getche( );
Example: ch = getche( );

3. getchar – a function used to input a single character from the keyboard, the character pressed echoed on the monitor, terminated by pressing ENTER key.
Syntax: getchar( );
Example: ch = getchar( );


4. gets – a function used to input sequence of character from the keyboard, spaces are accepted, terminated by pressing enter key.
Syntax: gets( );
Example: gets(ch);

5. scanf – a function used to input single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.
Syntax: scanf(“control string codes”, identifier);
Example: scanf(“%d”, &num);


Output Statement:-

A statement used to display the argument list or string on the monitor.

1. printf – a function used to display the argument list on the monitor. It sometimes needs the control string codes to help display the remaining argument on the screen.
Syntax: printf(“control string codes”, argument list);
Example: printf(“Hello, %s, you are %d years old”, name, age);

2. putchar – a function used to display the argument list or string on the monitor. It is like overwriting a character.
Syntax: putchar( );
Example: putchar(tolower (ch));

3. puts – a function used to display the argument list or string on the monitor. It does not need the help of the control string codes.
Syntax: puts( );
Example: puts(“hello”);

Wednesday, 12 November 2014

Electrostatics


Electrostatics:-

• Electrostatics is the study of electric charge at rest.
(Or more or less at rest, in contrast with current electricity.)


Electrical Charges:-

• Electric charge is a fundamental property of matter.

Two types of electric charges:
• Positive charge - every proton has a single positive charge.
• Negative charge - every electron has a single negative charge.


• An object with an excess of electrons is negatively charged.
• An object with too few electrons (too many protons) is positively charged.
• An object with the same number of electrons and protons is neutral.


• Like charges repel.
• Opposite charges attract.

Elementary Charges:-

• Protons carry the smallest positive charge.
• Protons and uncharged neutrons generally reside in an atom’s nucleus.
• Protons are held in the nucleus by the strong force.

• The smallest negative charge is the charge on the electron.
• In normal atoms, electrons orbit the nucleus.
• The electric force between electrons and protons supplies the centripetal force to keep electrons in the atom.

• The charges carried by the proton and electron are equal in size.
• The mass of the proton is about 2000 times the mass of the electron.


Units of Charge:-

• The SI unit of charge is the Coulomb.

1 Coulomb = the charge of   (6.24 x 10^18)   electrons.

e   =   (1.602 x 10^-19)   C


Charge is Conserved:-

• Electric charge is conserved:
– Electric charge moves from one place to another: (no case of the net creation or destruction of electric charge has ever been observed.)
• In solids, only electrons can move.
• In liquids, gasses, and plasma, both positive and negative ions are free to move.


Sunday, 2 November 2014

Integrated Development Environment (IDE)



Integrated Development Environment:-
                         
                An integrated development environment (IDE), also known as integrated design environment and integrated debugging environment, is a type of computer software that assists computer programmers in developing software.
IDEs normally consist of a source code editor, a compiler and/or interpreter, build-automation tools, and (usually) a debugger.

Source code editor: It is a text editor program designed specifically for editing source code of computer programs by programmers. Source code editors may have features specifically designed to simplify and speed up input of source code, such as syntax highlighting and auto complete.

Compiler: It is a computer program (or set of programs) that translates text written in a computer language (the source language) into another computer language (the target language).

Interpreter: It is a computer program that executes, or performs, instructions written in a computer programming language.

Debugger: It is a computer program that is used to test and debug other programs.