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

Important Questions of Data Structure and Algorithm (DSA)

 . 1. What is Data structure? Explain different operations to be performed on data structure. 2. Define stack as ADT. Convert P+Q-(R*S/T+U) - V*W into infix expression to postfix. 3. Define Queue. Explain its type with example. 4.  Difference between stack and Queue. 5. Difference between Linear Queue and circular Queue. 6. Write an algorithm to enqueue and dequeue data element in a circular queue.                              7. Define Linked List. Explain its type. How does double linked List is different from circular linked   List. 8. What is recursion and recursive function? write a recursive function to compute Fibonacci number. 9. What is an AVL tree ? Create an  AVL tree from the following data:      18, 12, 14, 8, 85, 25, 31, 24, 27 10. Define B-tree? How to insertion and deletions of elements can be done in a B-tree. 11. Create an B-tree from the following Data:  ...

BCA Math II old question model solution

 . BCA Math II question model 2018: BCA Math II question model 2019: BCA Math II question model 2020:

Define LAN and WAN

 . Local Area Network (LAN)  A LAN is a network that is used for communicating among computer devices, usually within an office building or home.   LAN’s enable the sharing of resources such as files or hardware devices that may be needed by multiple users • • Is limited in size, typically spanning a few hundred meters, and no more than a mile.  Is fast, with speeds from 10 Mbps to 10 Gbps.  Requires little wiring, typically a single cable connecting to each device.  Has lower cost compared to MAN’s or WAN’s.  LAN’s can be either wired or wireless. Twisted pair, coax or fiber optic cable can be used in wired LAN’s. Advantages of LAN :    The data is transferred at an extremely faster rate in local Area Network.  Local area network (LAN) provides higher security. Disadvantages of LAN :   Initial cost of installing local area network is quite high.  Unauthorized user can access critical data of an organization in case LAN ad...