Showing posts with label High School. Show all posts
Showing posts with label High School. Show all posts

Thursday, July 14, 2011

Unicode vs ASCII


Unicode vs ASCII
Unicode and ASCII both are standards for encoding texts. Uses of such standards are very much important all around the world. Code or standard provides unique number for every symbol no matter which language or program is being used. From big corporation to individual software developers, Unicode and ASCII have significant influence. Communication between different regions in the world was difficult but this was needed in every time. Recent easiness in communication and development of a unique platform for all people in the world is the result of inventing some universal encoding system.
Unicode
Development of Unicode was coordinated by a non-profit organization Unicode Consortium. Unicode is most compatible with different language like Java, XML, Microsoft .Net etc. Symbolic figure or glyptic art are greatly available due to modification of character shape which is done using some mechanism adopted by Unicode. Invention of Unicode has brought major renovation in texture, graphics, themes etc. Natural numbers or electrical pulse is used to convert a text or picture and they are easy to transmit through different networks.
• Recent version of Unicode consist more than 109000 characters, charts for visual reference, encoding methodology, standard for encoding, collation, two-way display, depicting etc.
• UTF-8 is one of the widely used encodings.
• Unicode consortium consists of world leading software and hardware companies like Apple, Microsoft, Sun Microsystems, Yahoo, IBM, Google Oracle Corporation.
• First book was published by the consortium in 1991 and latest Unicode 6.0 published in 2010.
ASCII
Short form of American Standard Code for Information Interchange is ASCII. Encoding of that system is based on ordering the English alphabet. All modern data encoding machines support ASCII as well as other. ASCII was first used by Bell data services as a seven bit Tele-printer. Use of binary system had brought tremendous change in our personal computing. Personal Computer as we see now is the boon of using binary language which was used as core things for encoding and decoding. Various languages later created and adopted are based on it. As binary system makes the PC more comfortable and user friendly for all, similarly ASCII is being used for making easiness in communicating. 33 characters are non-printing, 94 printing characters and space altogether makes 128 characters which are used by ASCII.
• It allows 128 characters.
• WWW or World Wide Web used ASCII as character encoding system but now ASCII is superseded by UTF-8.
• Short passage was encoded by early ASCII.
• ASCII-code order is different from traditional alphabetical order.
Difference between Unicode and ASCII
• Unicode is an expedition of Unicode Consortium to encode every possible languages but ASCII only used for frequent American English encoding. For example, ASCII does not use symbol of pound or umlaut.
• Unicode require more space than ASCII.
• Unicode use 8, 16 or 32 bit characters based on different presentation while ASCII is seven-bit encoding formula.
• Many software and email can’t understand few Unicode character set.
• ASCII only supports 128 characters while Unicode supports much more characters.
Though different variations appear among Unicode and ASCII but both are very much essential in development of web based communication.

ASCII


ASCII
Short form of American Standard Code for Information Interchange is ASCII. Encoding of that system is based on ordering the English alphabet. All modern data encoding machines support ASCII as well as other. ASCII was first used by Bell data services as a seven bit Tele-printer. Use of binary system had brought tremendous change in our personal computing. Personal Computer as we see now is the boon of using binary language which was used as core things for encoding and decoding. Various languages later created and adopted are based on it. As binary system makes the PC more comfortable and user friendly for all, similarly ASCII is being used for making easiness in communicating. 33 characters are non-printing, 94 printing characters and space altogether makes 128 characters which are used by ASCII.
• It allows 128 characters.
• WWW or World Wide Web used ASCII as character encoding system but now ASCII is superseded by UTF-8.
• Short passage was encoded by early ASCII.
ASCII-code order is different from traditional alphabetical order.
Difference between Unicode and ASCII
• Unicode is an expedition of Unicode Consortium to encode every possible languages but ASCII only used for frequent American English encoding. For example, ASCII does not use symbol of pound or umlaut.
• Unicode require more space than ASCII.
• Unicode use 8, 16 or 32 bit characters based on different presentation while ASCII is seven-bit encoding formula.
• Many software and email can’t understand few Unicode character set.
• ASCII only supports 128 characters while Unicode supports much more characters.
Though different variations appear among Unicode and ASCII but both are very much essential in development of web based communication.

Compiler vs Interpreter


Compiler and interpreter, both basically serve the same purpose. They convert one level of language to another level. A compiler converts the high level instructions into machine language while an interpreter converts the high level instruction into some intermediate form and after that, the instruction is executed.
Compiler
A compiler is defined as a computer program that is used to convert high level instructions or language into a form that can be understood by the computer. Since computer can understand only in binary numbers so a compiler is used to fill the gap otherwise it would have been difficult for a human to find info in the 0 and 1 form.
Earlier the compilers were simple programs which were used to convert symbols into bits. The programs were also very simple and they contained a series of steps translated by hand into the data. However, this was a very time consuming process. So, some parts were programmed or automated. This formed the first compiler.
More sophisticated compliers are created using the simpler ones. With every new version, more rules added to it and a more natural language environment is created for the human programmer. The complier programs are evolving in this way which improves their ease of use.
There are specific compliers for certain specific languages or tasks. Compliers can be multiple or multistage pass. The first pass can convert the high level language into a language that is closer to computer language. Then the further passes can convert it into final stage for the purpose of execution.
Interpreter
The programs created in high level languages can be executed by using two different ways. The first one is the use of compiler and the other method is to use an interpreter. High level instruction or language is converted into intermediate from by an interpreter. The advantage of using an interpreter is that the high level instruction does not goes through compilation stage which can be a time consuming method. So, by using an interpreter, the high level program is executed directly. That is the reason why some programmers use interpreters while making small sections as this saves time.
Almost all high level programming languages have compilers and interpreters. But some languages like LISP and BASIC are designed in such a way that the programs made using them are executed by an interpreter.
• A complier converts the high level instruction into machine language while an interpreter converts the high level instruction into an intermediate form.
• Before execution, entire program is executed by the compiler whereas after translating the first line, an interpreter then executes it and so on.
• List of errors is created by the compiler after the compilation process while an interpreter stops translating after the first error.
• An independent executable file is created by the compiler whereas interpreter is required by an interpreted program each time.


What is the difference between primary & secondary storage device?


PRIMARY STORAGE DEVICES            SECONDARY STORAGE DEVICES

1.These devices are tempo-      1.These devices are permanent.
rary.                       
2.These devices are expensive.  2.These are cheaper.
3.These devices are faster,     3.These devices Computers via 
therefore expensive.            cables,and slow, therefore 
                                cheaper.
4.These devices have less       4.These devices have high 
storage capacity.               storage capacity.
5.These devices refer to RAM.   5.These devices refer to FDD

Difference between primary and secondary memory.

The primary memory or the main memory is part of the main computer system. The processor or the CPU directly stores and retrieves information from it. This memory is accessed by CPU, in random fashion. That means any location of this memory can be accessed by the CPU to either read information from it, or to store information in it.
o The primary memory itself is implemented by two types of memory technologies. The first is called Random Access Memory (RAM) and the other is read only memory (ROM). A more appropriate name for RAM is RWM (Read Write Memory), the CPU can write and read information from any primary memory location implemented using RAM. The other part of primary memory is implemented using ROM which stands for Read Only Memory.


Primary memory is much faster and also it is more cost effective. But the secondary memory is much slower and also less costly. It stores the data permanently unless it is erased. The secondary memory is usually available in the form of floppy disk storage media, hard disk, CD, DVD, Pen drive (i.e. Mass storage devices), memory chips. A 5 and1/4 inch floppy disk typically stores 1.44 mb of data. The data on the floppy disk is organized in terms of tracks and sectors. Hard disk can have large capacity something like 80-300 GB's or higher. Hard disk itself is made up of, large number of platters. Hard disk is usually much faster compared to floppy disk. CD can store up to 750 mb of data. Information on CD ROM is organized in terms of a spiral track. A DVD is digital Versatile Disk and can store 4.6 Gigabyte of information. All these CD disk are usually write ones and read many times (if the disk is not multisession and re writable). So are the DVDs.


INTRODUCTION TO COMPUTER IX

INTRODUCTION TO COMPUTER

Introduction

A computer is an electronic machine that accepts instruction as input data, stores the data, processes them and produces the desired output. Computer automatically accepts data and instructions as input, stores and processes them and produces and gives the output under the control of the instructions of the stored programs.

Features of computer:

As computer is an intelligent amplifier that performs the above-mentioned operations in a faster, accurate and efficient way, it creates extra leisure time which can be used in matters involving creativity & judgment. Some of the common characteristics possessed by computers are as follows:
  • A computer can perform tasks at very high speed. The speed, with which computers carry out these operations, varies from a few microseconds (10-6 of a second or millionth of a second) to nanoseconds (10-9 of a second or billionth of a second).
  • It can store a large amount of data in its memory forever
  • It gives 100% accurate outputs unless the wrong data and instructions are entered.
  • Once the data and instructions are given, it caries out its operation automatically to produce the desired output.
  • It can perform its tasks repetitively with same speed, efficiency and accuracy, without being affected by traits of tiredness and lack of concentration.
  • It is versatile in a sense that it can perform from simple tasks, such as Desktop Publishing, to advanced tasks, such as controlling of automatic weapons, satellite launching, etc.

Limitations of Computers:

  • Since computer does not have its own intelligence, it should be given instructions to carry out its tasks. However, the fifth generation is supposed to have own intelligence.
  • An important data can be lost sometimes due to the breakdown of storage media in machine.
  • However there are various systems to protect data, but there is always fear of data piracy.
  • Computer is a very expensive to install and maintain that it would be difficult to afford it for everybody. But, with the ever-increasing advances being made in the state of the art, the cost of computer equipment has dropped drastically over the years. Hardware costs have been decreasing at an estimated annual rate of 25%.
  • Computers cannot store data unless they are given instructions.

SWITCH-CASE STATEMENT

SWITCH-CASE STATEMENT

Switch Statements

The switch and case statements help control complex conditional and branching operations. The switch statement transfers control to a statement within its body.
Syntax:
The general form of a switch statement is:
switch (variable)
{
    case expression1:
        do something 1;
        break;
    case expression2:
        do something 2;
        break;
      ....
    default:
        do default processing;
}

Example :
#include<stdio.h>
 
main()
{
    int x;
 
    printf("Enter the any number");
    scanf("%d", &x);
 
    switch(x)
{
 case 1:
    printf("I am in Case one");
    break;
 case 2:
    printf("I am in case two");
    break;
 case 3:
    printf("I am in case three");
    break;
 default:
    printf(" I am in Default");
}
}
 
In above program if we enter 1 value in x then the output will be:
I am in Case one
When an expression is found that is equal to the tested variable, execution continues until a break statement is encountered. It is possible to have a case without a break. This causes execution to fall through into the next case. This is sometimes very useful.

STORAGE CLASSES : Programming

STORAGE CLASSES

Introduction

The storage class determines the part of memory where storage is allocated for an object (particularly variables and functions) and how long the storage allocation continues to exist.
A scope specifies the part of the program which a variable name is visible, that is the accessibility of the variable by its name.  In C program, there are four storage classes: automatic, register, external, and static.
Moreover, a variable's storage class tells us:
  • Where the variable would be stored
  • What will be the initial value of the variable, if initial value is not specifically assigned(i.e. the default initial value)
  • What is the scope of the variable; i.e. in which functions the value of the variable would be available.
  • What is the life of the variable; i.e. how long would the variable exist.

Automatic Storage Class

The features of a variable defined to have an automatic storage class are as under
Storage
Memory
Default initial value
Garbage value
Scope
Local to the block in which the variable is defined
Life
Till the control remains within the block in which the variable is defined
  • The scope of automatic variables is local to the block in which they are declared, including any blocks nested within that block. For these reasons, they are also called local variables.
  • No block outside the defining block may have direct access to automatic variables (by variable name) but, they may be accessed indirectly by other blocks and/or functions using pointers.
  • Automatic variables may be specified upon declaration to be of storage class auto. However, it is not required to use the keyword auto because by default, storage class within a block is auto.
  • Automatic variables declared with initializers are initialized every time the block in which they are declared is entered or accessed.
  • auto is the default storage class for local variables.

Example
void main()    
{
    int Count;
    auto int Month;
}
The example above defines two variables with the same storage class. auto can only be used within functions, i.e. local variables.

Register Storage Class

The features of a variable defined to have an automatic storage class are as under
Storage
CPU Register
Default initial value
Garbage value
Scope
Local to the block in which the variable is defined
Life
Till the control remains within the block in which the variable is defined
  • Registers are memory located within the CPU itself where data can be stored and accessed quickly. Normally, the compiler determines what data is to be stored in the registers of the CPU at what times.
  • register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and can't have the unary '&' operator applied to it (as it does not have a memory location).
Example:
      void main()
      {
        register int  Miles;
      }

Static Storage Class

The features of a variable defined to have an automatic storage class are as under
Storage
Memory
Default initial value
Zero
Scope
Local to the block in which the variable is defined
Life
Value of the variable persists between different function calls
  • Static automatic variables continue to exist even after the block in which they are defined terminates. Thus, the value of a static variable in a function is retained between repeated function calls to the same function.
Comparing two storage class we get to know how static storage class variable works and auto storage class works.
Auto Storage Class
Static Storage Class
void Increment()
{
    auto int i=1;
    printf("%d\n",i);
    i=i+1;
}
void main()
{
    Increment();
    Increment();
    Increment();
}
void Increment()
{
    static int i=1;
    printf("%d\n",i);
    i=i+1;
}
void main()
{
    Increment();
    Increment();
    Increment();
}
Output:
1
1
1
Output:
1
2
3
Each time the Increment() function is called i variable is taken as new and each time i is initialized with 1 so when i is printed each time it displays 1
When first time Increment() function is called i variable is initialized to 1 and next two time the value will be incremented by one. That is when Increment() function is called second time i variable in not initialized again but will directly goto printf() and displays the value of i i.e. 2 and so on it displays 3

External Storage Class

The features of a variable defined to have an automatic storage class are as under
Storage
Memory
Default initial value
Zero
Scope
Globle
Life
As long as the program's execution doesn't come to an end
  • All variables we have seen so far have had limited scope (the block in which they are declared) and limited lifetimes (as for automatic variables).
  • However, in some applications it may be useful to have data which is accessible from within any block and/or which remains in existence for the entire execution of the program. Such variables are called global variables, and the C language provides storage classes which can meet these requirements; namely, the external (extern) and static (static) classes.
  • Declaration for external variable is as follows:
  • extern int var;
  • External variables may be declared outside any function block in a source code file the same way any other variable is declared; by specifying its type and name (extern keyword may be omitted).
Example:
#include<stdio.h>
extern int i;    
void Increment()
{    
      i=i+1;
      printf("%d\n",i);
}
void Decrement()
{    
      i=i-1;
      printf("%d\n",i);
}
void main()
{    
      printf("initial value=%d\n",i);
      Increment();
      Increment();
      Decrement();
      Decrement();
}

          Output:

                    initial value = 0
                    1
                    2
                    1
                    0


Book : Let us C

INPUT/OUTPUT : Programming

INPUT/OUTPUT
Usually i/o, input and output, form an important part of any program. To do anything useful your program needs to be able to accept input data and report back your results. In C, the standard library provides routines for input and output. The standard library has functions for i/o that handle input, output, and character and string manipulation. In this lesson, all the input functions described read from standard input and all the output functions described write to standard output. Standard input is usually the keyboard. Standard output is usually the monitor.

Formatted Output

The standard library function printf is used for formatted output. It takes as arguments a format string and an optional list of variables or literals to output. The variables and literals are output according to the specifications in the format string. Here is the prototype for printf.
int printf(const char *format, arg1, arg2, arg3, ......);
Example: Adding two number
#include
#include
void main()
{
    int a,b,c;
    printf("enter the value for a and b");
    scanf("%d %d", &a, &b);

    c= a + b;

    printf("%d + %d = %d" ,a ,b ,c);
    getch();
}
Here are the more common conversion specifiers.
Specifier
Argument Type
%d
int
%f
float or double
%e
float or double, output in scientific notation.
%c
character
%s
character string (char *)

Formatted Input Output

The standard library function scanf is used for formatted input. It takes as its arguments a format string and a list of pointers to variables to store the input values. Similar to its use in printf, the format string can contain literals and conversion specifiers. In C, to return a value from a function to a calling routine, a pointer to a variable is passed into the function. A pointer stores the memory address of another variable. The methods of passing and returning values from functions are described in Passing Arguments to Functions. Don't worry if you don't understand pointers completely. For now, all this means is a slightly different notation in the call to scanf. In later lessons, pointers and functions will be fully explained. Here is the prototype of scanf and a program illustrating its use.
Scanf returns an integer, either the number of values read in, or EOF if an end of file is reached. EOF is a special termination character, specified in stdio.h, which designates the end of a file. If no values are successfully read, scanf returns 0. To use scanf in a program, the file stdio.h must be included.

WAP to find out simple interest (SI) and Amount (A), given that SI=PRT/100 and A=P+SI.
#include<stdio.h>
#include<conio.h>
void main()
{
   float p,t,r,A,SI;
   printf("Enter value p, t, r ");
   scanf("%f %f %f",&p,&t,&r);

   //calculating simple interest
   SI=(p*t*r)/100;

   //calculating Amount
   A=SI+p;

   printf("Simple interest=%f, Amount=%f", SI, A);
   getch();
}

Unformatted Input / Output

Unformatted functions do not allow the user to read or display data in desired format. These library functions basically deal with a single character or a string of characters. The functions getchar(), putchar(), gets(), puts(), getch(),gerche () , putch() are considered as unformatted functions.

getchar and putchar

getchar reads a single character from standard input.
putchar writes a single character to standard output.
Example:
#include<stdio.h>
void main()
{
    char c;

    c = getchar(); /* to take input form keyboard */
    putchar(c);    /* to display value of 'c' in screen */
}

gets and puts

gets reads a line of input into a character array (String).
puts writes a line of output to standard output .
Example:
#include<stdio.h>
void main()
{
     char str[120]; /* Holds input and output strings */
     gets(str); /* to take string as input form keyboard */
     puts(str); /* to display value of 'str' string in screen */
}

FILE HANDELING

FILE HANDELING

File Input and Output


Library Functions for File I/O.

fopen is used to open a file for formatted I/O and to associate a stream with that file. A stream is a source or destination of data. It may be a buffer in memory, a file or some hardware device such as a port.
FILE *fp;
fp=fopen(filename, mode);
fopen() returns a file pointer on success or NULL on failure. The file pointer is used to identify the stream and is passed as an argument to the routines that read, write or manipulate the file. The filename and mode arguments are standard null-terminated strings. The valid modes are shown below.
Mode Use
"r" Read Mode.If the file exists, loads it into memory and sets up a pointer which points to the first character in it. If the file doesn't  exist it returns NULL.
Operations Possible:- reading from the file
"w" Write Mode. If the file exists, its contents are overwritten. If the file doesn't exist, a new file is created. Returns NULL, if unable to open file.
Operations Possible:- writing to the file
"a" Append Mode. If the file exists, loads it into memory and sets up a pointer that points to the last character in it. If the file doesn't exist, a new file is created. Returns NULL, if unable to open file
Operations Possible:- adding new contents at the end of file
"r+" Read Plus Mode. If the file exists, loads it into memory and sets up a pointer which points to the first character in it. If the file doesn't  exist it returns NULL.
Operations Possible:- reading existing contents, writing new contents, modifying existing contents of the file
"w+" Write Plus Mode. If the file exists, its contents are destroyed. If the file doesn't exist, a new file is created. Returns NULL, if unable to open file.
Operations Possible:- writing new contents, reading them back and modifying existing contents of the file
"a+" Append Plus Mode. If the file exists, loads it into memory and sets up a pointer that points to the first character in it. If the file doesn't exist, a new file is created. Returns NULL, if unable to open file
Operations Possible:- reading existing contents, appending new contents to the end of file. Cannot modify existing contents.
Files are closed with the function fclose. Its prototype is:
fclose(*fp);

Functions for Reading and Writing to the file

fprintf():

Data is written to a file using fprintf. This function is very similar to printf. Printf was used to write to standard output, stdout. Fprintf has one additional argument to specify the stream to send data. Its prototype is:
fprintf(FILE *stream, const char* format, ....);

fscanf():

Data is read from a file using fscanf. This function is very similar to scanf, is used to read from standard input, stdin. Fscanf has one additional argument to specify the stream to read from. Remember that the argument to store data must be pointers.
fscanf(FILE *stream, const char* format, ....);

Other Useful Standard Library Functions for Input and Output

int fgetc(FILE *stream);
This function returns the next character in the input stream, or EOF if the end of the file is encountered. It returns int rather than char because the "end of file", EOF, character must be handled. EOF is an int and is too large to fit in a char variable.
int *fgets(char *s, int n, FILE *stream);
It returns a pointer to the character string if successful, or NULL if end of file is reached or if an error has occurred. The string is also read into the character array specified as an argument. The character string will be terminated be a "\0", which is standard for C.
At most n-1 characters will be read. This allows for storage of the string terminator, '\0'.
fputs(const char s*, FILE *stream);
This function writes a string to the stream. It returns EOF on failure.
int fputc(int c, FILE *stream);
fputc writes a single character to the output stream i.e. file. It returns EOF on failure.
int sprintf(char *buffer, const char *format, ...);
This function is the same as fprintf, except data is written into a character buffer rather than an output stream.
int sscanf(char *buffer, const char *format, ...);
This function is the same as fscanf, except data is read from a character buffer rather than an input stream.

Example 1: Here is the example program which creates a file "Record.txt" and adds students record in it.
#include<stdio.h>

main()
{
    char name[30];
    int idNum;
    FILE *fp;

    /* Open file for input */
    fp = fopen("Record.txt","w");
if(fp==NULL)
{
    printf("Error Opening File !!!");
    exit(1);
}
 
printf("Enter name and id")
scnaf("%d %s", name, &idNum);
 
/* Write out data */
fprintf(fp,"%d %s\n",idNum, name);
 
/* Close Files */
fclose(fp);
}
Example 2: Here is the example program which reads name and id form student record a file "Record.txt" and displays on screen.
#include<stdio.h>

main()
{
    char name[30];
    int idNum;
    FILE *fp;

    /* Open file for read */
    fp = fopen("Record.txt","r");
if(fp==NULL)
{
      printf("Error Opening File !!!");
      exit(1);
}
/*reading all records form file */
while(fscanf(fp,"%d %s", &idNum, name) != EOF)
          printf("%d %s\n", idNum, name);
 
/* Close Files */
fclose(fp);
}
Example: Create a file name "COLLEGE.DAT". Write a program to store record of n students in a file. These records contain student name, roll no, program. Also display records of those students whose program is BBAII and BCA II.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define N 2 //defining the N no. of student
void main()
{  
    struct student
    {
          int roll_no;
          char name[25],program[25];            
    };
    struct student s;
    int i;
    FILE *fp;
 
    fp = fopen ("COLLEGE.DAT ", "w+");
    if (fp == NULL);
    {
          puts("Cannot open file");          
          exit(0);
    }    
    //taking student records as input and writing it into file
    for(i=0;i<N;i++)
    {
          scanf("%d %s %s %d",&s.roll_no,s.name, s.program);
          fwrite(&s,sizeof(s),1,fp);//writing record into file
    }
   
    //reading from file until end of file
    while(fread(&s,sizeof(s),1,fp)!=EOF)
    {    
          //displaying only those records having program is BBAII or BCAII
          if(strcmp(s.program,"BBAII")==0||strcmp(s.program,"BCAII")==0)
                printf("%d\t %s\t %s\n",s.roll_no,s.name,s.program); 
    }    
    fclose(fp);
    getch();
}

STRUCTURE

STRUCTURE

Structures


Structures are used to group a number of different variables together which enables us treat a number of different variables stored in different place in memory.

Syntax:

struct structure_name
{
Data_type member;
........
};
struct structure_name  structure_variable;

Declaring Structures

A structure is declared by using the keyword struct followed by an optional structure tag followed by the body of the structure. The variables or members of the structure are declared within the body. Here is an example of a structure that would be useful in representing the book containing id, name of book and price.
struct book {
   int id;
   char name[25];
    float price;
};
The struct declaration is a user defined data type. Variables of type book may be declared similarly to the way variables of a built in type are declared.
struct book b1, b2;

Example: Simple example to declare structure and performing input/output process.
#include<stdio.h>
#include<conio.h>
main()
{
struct book
{
      int id;
      char name[25];
      float price;
};
struct book b1;
 
printf("Enter the record of book");
scanf("%d %s %f", &b1.id, b1.name, &b1.price);
 
//displaying the book record
printf("%d %s %f", b1.id, b1.name, b1.price);
 
getch();
}

Arrays of Structures

The data structures needed to solve some problems are best represented as an array of structures. Consider, for instance, the problem of storing 100 books record. Here we need to declare book variable like b1, b2, b3 and so on to b100, which is very hard way of doing so. So, this problem can be made easier by using array of structure. Array of structure is declared as follows:
struct book{
    int id;
    char name[25];
    float price;
    };
struct book b[100];
Example: Here is a simple program to illustrate the use of some of these array of structure. This program will input 100 book record and finds out the number of books price above 300.
#include<stdio.h>
#include<conio.h>
main()
{
struct book
{
      int id;
      char name[25];
      float price;
};
struct book b[100];
int i, ctr=0;
 
printf("Enter the 100 records of book");
for(i=0; i<100; i++)
      scanf("%d %s %f", &b[i].id, b[i].name, &b[i].price);
 
//finding out the book record whose price is above 300
for(i=0; i<100; i++)
{
if(b[i].price > 300)
      ctr = ctr +1;
}
 
printf("No. of books having price above 300 is %d", ctr);
 
getch();
}

Nested Structure

When a structure is created at first and then again is called by another structure as a member of it. We call this mechanism as nested structure. In another simply can say, structures can contain other structures as members then we call it as nested structure.

 Declaration:

struct Date
{
int dd, mm, yy;
};
struct book
{
int id;
char name[25];
float price;
struct Date issue;
};
struct book b;

Example:

    #include<stdio.h>
    void main()
    {
          struct Date
          {
                int dd, mm, yy;              
          };
          struct student
          {
                int roll;
                char name[25]
                struct Date dob;       
          };
          struct student s;
         
          //taking input in normal structure
          scanf("%d %s",&s.roll, name);
          //taking input in nested structure
          scanf("%d %d %d",&s.dob.dd, &s.dob.mm, &s.dob.yy);
         
          //Displaying the value of structure
          printf("%d %s",s.roll, name);
          //Displaying the value of nested structure
          printf("%d %d %d",s.dob.dd, s.dob.mm, s.dob.yy);
         
          getch();      
    }