Sunday, March 29, 2015

Sieve Algorithm of finding prime number

To find all the prime numbers less than or equal to a given integer n by Sieve Eratosthenes' method:

1.    Create a list of consecutive integers from 2 to n: (2, 3, 4, ..., n).
2.    Initially, let p equal 2, the first prime number.
3.    Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list.
      These numbers will be 2p, 3p, 4p, etc.; note that some of them may have already been marked.
4.    Find the first number greater than p in the list that is not marked.
      If there was no such number, stop. Otherwise, let p now equal this number (which is the next prime), and repeat from step 3.

Friday, April 19, 2013

memory allocation for 2D array

the memory of a computer is linear and not a matrix like a 2D array. So, the elements of the array are stored either by row, called "row-major", or by column, called "column-major". Row-major order is used most notably in C and C++ during static declaration of arrays.
In C, since the length of each row is always known, the memory can be filled row one row at a time, one after the other.
Example:
a[i][j] =
1 2 3 4 5 6 7 8 9
Representation in the memory: In row-major: 1 2 3 4 5 6 7 8 9 In column-major: 1 4 7 2 5 8 3 6 9
Address calculation of an element:

Row-Major :
addr (i,j) = B + W * ( Nc * (i - Lr) + (j-Lc) )

Monday, March 25, 2013

Array in c prograqmmming




There are times while writing C code, you may want to store multiple items of same type as contiguous bytes in memory so that searching and sorting of items becomes easy. For example:
  1. Storing a string that contains series of characters. Like storing a name in memory.
  2. Storing multiple strings. Like storing multiple names.
C programming language provides the concept of arrays to help you with these scenarios.

Saturday, March 23, 2013

Function in C Programming



                                           function



A  function is an independent
section of program code that performs a certain task and has been assigned a name.

 By  referencing a function’s name, your program can execute the code in the function.

Tuesday, March 19, 2013

Volt-Ampere Characteristics of pn Junction




Volt-ampere or V-I characteristic of a  pn  junction (also called a  crystal or semiconductor diode) is the
curve between voltage across the junction and the circuit current.  Usually, voltage is taken along  x-
axis and current along  y-axis. The below  fig.1  shows the  circuit arrangement for determining the  V-I
characteristics of a  pn  junction. The characteristics can be studied under three heads, namely;    zero     external voltage ,   forward bias and   reverse bias .

                                             Figure:1