Skip to main content

Describe array and string functions and apply them

 .

Array

An array is a variable that can hold multiple value of similar datatype in continuous memory location. The value are accessed by index. The duffel  index of array start from zero and increase continuously by one. 
Syntax :
    <datatype> <variable name> [size];
Example :
    int roll[20];
    float salary[20];
    char name[10];

Types of array
Thera are two types of array which are given bellow :
  • One Dimensional array 
  • Multi Dimensional array

One Dimensional array

One dimensional array can represent in a single row. It is a structured collection of components (often called array elements) that can be accessed individually by specifying the position of a component with a single index value. 
Syntax :
    <data type> <variable name> [size];
Example 
  Write a program to enter to number in any array and find largest among them.
#include<stdio.h>
#include<conoi.h>
        void main( )
            { int i, num[10], l;
                    clrscr( );
            printf("Enter 10 number into array: ");
                for(i=0, i<10; i++)
            { scanf("%d", &num[i]); }
                l = num[0];
            for (i=0; i<10; i++)
                { if(num[i]>l)
                    {l = num[i]; } }
            printf("Largest = %d", l);
                    getch( );
                        }

Write a program to enter the n term number into array & sort them in ascending other. 
#include<stdio.h>
#include<conio.h>
          void main( )
                { int n, i, j, num[50], temp;
                        clrscr( );
                printf("Enter nth number: ");
                scanf("%d", &n);
            printf(" Enter nth value into array: ");
                for(i=0; i<n; i++)
            { scanf("%d", &num[i];}
                    /* sorting Loop */
            for (i=0; i<n; i++)
                { for (j=0; j<n; j++)
                {if(num[i]<num[i])
                    { temp = num[i];
                        num[i] = num[i];
                        num[j]= temp; }}}
            printf(" Starting value: ");
                for(i=0; i<n; i++)
            printf("%d\t", num[i]);
                    getch( );
                        }
                        

Multi Dimensional array 

An array which having two or more then two dimensional which specifies row, column and height. In two dimensional array referred to as matrix which contain two dimension row & column.

Syntax
<datatype> <array name> [size] [size] [size]

Example
Write a program to enter 2*2 matrix and calculate sum.
#include<stdio.h>
#include<conid.h>
        void main( )
            { int i, j, s[2][2];
                int a[2][2] = { (2,3), (5,6) };
                int b[2][2] = { (2,4), (5,8) };
                    clrscr( );
        // Matrix adding Loop
            for(i=0; i<2; i++)
                { for(j=0; j<2; j++)
                    { s[i][j] = a[i][j] + b[i][j]; } }
            printf("resultant matrix\n");
                for(i=0; i<2; i++)
                    { for(j=0; j<2; j++)
            { printf("%d\t", s[i][j]); }
                printf("\n"); }
                    getch( );
                        }


Write a program to enter 3*3 matrix and calculate multiplaction.
#include<stdio.h>
#include<conio.h>
          void main( )
                { int i, j, k, a[3][3], b[3][3], c[3][3], s=0;
                        clrscr( );
                printf("Enter first number  matrix 3*3: ")'
                        for(i=0; i<3; i++)
                { scanf("%d", &a[i][j]); } }
                printf("Enter second matrix 3*3: ");
                        for (i=0; i<3; i++)
                        { for (j=0; j<3; j++)
                { scanf("%d", &b[i][j]); }
            // Matrix multiplication
                        for(i=0; i<3; i++)
                        { for(j=0; j<3; j++)
                                s=0;
                { for(k=0; k<3; k++)
                    { s = s + a[i][j] * b[k][j];
                            c[i][j] = s; } }
            printf("Result matrix\n");
                    for(i=0; i<3; i++)
                        { for (j=0; j<3; j++)
            { printf("%d\t", c[i][j]); }
                printf("\n"); }
                    getch( );
                        }


String 

Array of characters arrange one after another in continues memory is called string. A string is always terminated by a NULL character.

String Function

    Function which are used to manipulate string functions. These are following

1. Strlen( ):
    This function used to determine length of string. It return value which denote length of string in which number of character present in string. It not include NULL character.
Syntax :
    ien = strlen(string);

2. Strcpy( ): 
      This function is used to copy one string to another string. The function accept two string as a parameter and copies the second string into first string include NULL character.
    Syntax :
        strcpy(s1, s2);

3. Strcat( ):
    This function is used to concatenates two string i.e. appends one string at the end of other string. The function accept two string as a parameters and store the contents of second string at the end of first string. 
    Syntax :
        strcat(s1, s2);

4. Strcmp( ):
    This function is used to compare two string to find whether string are same or not.
    Syntax :
        stremp(s1, s2);

5. Strlwr( ): 
    This function is used to convert given string into revers other.
    Syntax :
         strlwr(s1);

6. Strupr( ):
    This function is used to convert lower case into upper case.
    Syntax :
        strupr(s1);

7. Strrev( ):
    This function is used to convert given string into revers other.
    Syntax :
        strrev(s1);



Comments

Popular posts from this blog

Introduce Linux, UNIX and Linux distribution.

 . Linux Linux is an open source operating system. The term Linux is actually referred to mean a kernel of Unix like operating system developed by a Finish software architect Linus Torvald. The name Linux is derived from Linus' Unix. Linux was originated from the inspiration of a small Unix like operating system MINIX by A.S Tanenbum. Linux is a complete multiuser, multiprocessing, secure and stable operating system which is also considered as UNIX clone. However no code from the proprietary from AT and T is included in Unix. It has flavor of Unix but is not Unix. UNIX  UNIX is a layered operating system. The innermost layer is the hardware that provides the service for the OS. The operating system, referred to in UNIX as the kernel, interacts directly with the hardware and provides the services to the user program. These user programs don't need to know anything about the hardware. They just need to know how to interact with the kernel and it's up to the kernel to provide ...

Introduction of Computer

.  A computer is an electronic device. It take input and store the data in memory and performing the function to produce accurate result in output device. It is used to type document, send email, play game, browse the web and entertainment.   Characteristics of computer  1 . High speed  Computer is very fast device. It is capable of performing calculation of very large amount of data. The computer has unit of speed in microsecond, nanosecond and even in picosecond. The computer is capable of performing millions of tasks per second. 2. Accuracy  The computer produces highly accurate and reliable result.  It does not make any kind of mistake in calculating. The calculation are 100% error free. The computers perform accurate 'n' number of times. 3. Storage capability A computer has much more storage capability. It can store large amount of data. It can store any type of data such as image, video, text document, audio and many more. 4. Diligence Diligence ...

Open System Interconnect (OSI) Reference Model

 . Open system interconnection (OSI) Model explains how packet travels through various layers to other devices on a network, even if the sender and destination have different types of network media. Layer 1(Physical layer):  Function  To activate, maintain, deactivate the physical connection.  To define voltage and data rates needed for transmission.  To convert the digital bits into electrical signals.  To decide weather the transmission the transmission is simplex, half or full duplex.  Physical layer doesn’t perform the detection and correction of errors. Layer 2 (Datalink layer):  Framing (stream of bits into manageable data units):  The datalink layer divides the stream of bits received from the network layer into frame manageable data units called frames.  Physical addressing (MAC Address):  Data link layer adds a header to header to the frame to define the sender and receiver of the frame. Flow Control (mechanism for overwhel...