EX NO : 05                      USAGE OF ARRAYS
DATE:
                                                                           REG:URK22cs3007
          1) Write a C program to perform the sum of all elements stored in
             an array.
        AIM:
           Find the sum of all stored array
        ALGORITHM:
             STEP 1: Start the program.
             STEP 2: Initialize arr[]
             STEP 3: Get the array from the user.
             STEP 4: sum
             STEP 5: Stop the program
        PROGRAM:
            #include <stdio.h>
            void main()
             {
            int arr[]={1,2,3,4,5,6,};
            int sum=0;
            int length=sizeof(arr)/sizeof(arr[0]);
           for(int i=0;i<length;i++)
           {
           sum=sum+arr[i];
            }
             printf("Sum of all elements of an array is : %d\n\n", sum);
              }
        OUTPUT:
        RESULT:
            The program is successfully executed.
 2) Write a C program to get 10 numbers from the user and find the largest
    and smallest number of the array along with the index value.
 AIM:
      Get number from user and find largest and smallest number.
 ALGORITHM:
        STEP 1: Start the program.
        STEP 2: Initialization of array.
        STEP 3: Get values from the user .
        STEP 4: Stop the program.
 PROGRAM:
#include<stdio.h>
  int main()
  {
       int a[10], Size, i, Minimum, Min_Position, Maximum, Max_Position;
      printf("\nPlease Enter the size of an array : ");
      scanf("%d",&Size);
      printf("\nPlease Enter %d elements of an array: \n", Size);
      for(i=0; i<Size; i++)
      {
           scanf("%d",&a[i]);
      }
      Minimum = a[0];
      Maximum = a[0];
      for(i=1; i<Size; i++)
      {
      if(Minimum > a[i])
      {
           Minimum = a[i];
           Min_Position = i;
           }
    if(Maximum < a[i])
      {
           Maximum=a[i];
           Max_Position = i;
      }
      }
       printf("\n Smallest element in an Array = %d", Minimum);
       printf("\n Index position of the Smallest element = %d", Min_Position);
       printf("\n Largest element in an Array = %d", Maximum);
       printf("\n Index position of the Largest element = %d", Max_Position);
       return 0;
  }
  OUTPUT:
 RESULT:
        The program is successfully executed and hence find the
largest and smallest number of an array
  3) Write a C program to implement linear search.
AIM:
   Write a C program to implement linear search.
ALGORITHM:
   STEP 1: Start the program.
   Step 2: Get the input value from user.
   Step 3: Size and element of an array.
   Step 4: Stop the program.
PROGRAM:
     #include<stdio.h>
    int main()
    {
    int a[20],i,x,n;
    printf(“How many elements?”);
    scanf(“%d”,&n);
    printf(“Enter array element:\n”);
    for(i=0;i<n;++i)
    scanf(“%d”,&a[i]);
      printf(“\nEnter element to search:”);
      scanf(“%d”,&x);
      for(i=0;i<n;++i)
      if(a[i]==x)
      break;
      if(i<n)
      printf(“Element found at index%d”,i);
      else
      printf(“Element not found”);
      return 0;
      }
      OUTPUT:
RESULT:
     The program is executed successfully and the size of array of the given
element is founded.
      4. Write a program in C to read n number of values in an array
      and display it in reverse order.
AIM:
    Write a C program to read a n number of values in array and
display it in reverse order.
ALGORITHM:
      STEP 1: Start the program.
      STEP 2: write a program
    STEP 3: get the n number of values from user
    STEP 4: Stop the program
PROGRAM:
     #include <stdio.h>
     int main()
     {
     int arr[] = {1, 2, 3, 4, 5};
     int length = sizeof(arr)/sizeof(arr[0]);
     printf("Original array: \n");
     for (int i = 0; i < length; i++) {
     printf("%d ", arr[i]);
     }
     printf("\n");
     printf("Array in reverse order: \n");
     for (int i = length-1; i >= 0; i--) {
         printf("%d ", arr[i]);
     }
     return 0;
}
OUTPUT:
RESULT:
     The program is successfully executed and the values of arrays are arranged
in a reverse order.