Академический Документы
Профессиональный Документы
Культура Документы
C-Programming
Date: 31/08/2014(Sun) Time : 11:00AM
onwards
Reference Book on C-language: ANSI C by E.
Balagurusamy, Publ: Tata McGraw Hill Book
Company
Some important Features of C-language:
1.
C is a high level language.
2.
C is very much case sensitive.
Normally we write C-program using small
letters. Most of the keywords of Clanguage consists of small letters.
3.
C is a function oriented language.
There should be at least one function
called as main(). We can use our own
functions in any C-program. A program
comprises of set of instructions.
4.
Any statement in C-language must be
terminated by a semicolon(;). Example :
y=5; x=2*x;
5.
All variables in C-language must be
defined first otherwise we can not use
those variables. Example:
int a,b;
float x,y;
6.
We can write comments in C-program
as follows:
/* This my comment */ .
So therefore a comment line will begin
with /* and should end with */
/* Write a program to calculate sum of
First n natural numbers */
7.
Arithmetic operators in C-language:
(i)
Addition operator : +
(ii) Subtraction operator : (iii) Multiplication operator : *
(iv) Division Operator : / (forward slash)
(v) Modulo operator : %
(vi) Pre-increment
operator/
Postincrement operator : ++
Example :
Post increment operator :x++; This
is equivalent to x=x+1;
Pre increment operator : ++x; It
means x=x+1;
(vii) Pre-dcrement
/
Post-decrement
operator : -Example:
--x
x=x-1 pre
decrement
x-- x=x-1 post
decrement
Logical Operator:
(1) Logical Not : !
&& T
&& F
&& T
&& F
=T
=F
=F
=F
Logical Or operator :
T
F
T
F
(xi)
||
||
||
||
F
T
T
F
=T
=T
=T
=F
a=5;
b=2*a;
c=a+b;
In 16-bit compiler the storage of
int type variable in memory is
equal to 2 bytes or 16 bits.
Calculate maximum value in 16bits where the most significant
bit(MSB) is used for the sign of
the number. If MSB=0 then the
value will be considered as +ve
value and if it is 1 then the value
will be considered as negative.
Maximum value we can store in
16 bits=215-1=32767
Minimum value we can store in
16 bits
=-215 =-32768
So we can store any number from
-32768 to +32767.
(2) float type variable or data: To
define any fractional data such as
1.234, -3.456 etc we have define
the variables as float a,b,c;
Example:
float a,b,c;
a=2.25; /* a=2.25 */
b=2;
/* b=2 */
c=a*b; /* c=2.25*2=4.5 */
Floating variables will be stored
in 4 bytes in memory. Out of 4
bytes 3 bytes are reserved for
factional part of a number and 1
byte is reserved for the exponent:
Example : x=123 1.23E02
1.23*102
The precision of number is up to
7 significant digits and the 7-th
digit is always rounded off.
Example :
float p=3.14159265358979284;
=3.141593 this value
will be stored in memory.
The maximum value of the order
of 1038
Note: floating variables are also
called single precision type
variable.
(3) double type variable/data :
To
define double type variable we
use a statement called double.
Example:
double
p=3.14159265358979284;
Now the storage will be made in
8 bytes or in 32 bits and the
precision of a number is up to 16
significant digit and the last digit
is always rounded off.
So there the value of p here will
be
stored
as
p=3.141592653589793
(4) long double type variable : To
define long double type variable
or data we use a statement
called long double.
Example : long double a,b,c;
Long double variable will occupy
10 bytes in the memory. The
precision of a number is up to 18
significant digit and last digit is
always rounded off. This is the
highest possible precision in Clanguage.
(5) long int type variable or data:
we define variable as
Step-4: c=1
Step-5: s1=s1+c
Step-6: s2=s2+s1
Step-7: c=c+1
Step-8: if c<=n then go to step-5
Step-9: Print s2
Step-10: end