Computer Programming C Laboratory: String C Programs

C Program to find the specified element from the array using Linear searching

Linear Search or Sequential Search - C Programming


/* Program to find the specified element from the array using Linear searching */

#include <stdio.h>

#include<conio.h>

main()

{

/* Local definitions */

int i,j,k, no,a[100], f=1;.

char c='y',ch;

/* Statements */

clrscr();

while(c == 'y'||c== 'Y')

{

          printf("\nEnter the size of sorting");

          scanf("%d", &no);

          printf("\nEnter the elements of the array");

          for(i=0;i<no;i++)

                    scanf("%d",&a[i]);

          printf("\nEnter the element to be searched");

          scanf("%d", &k);

          for(i=0;i<no;i++)

          {

                    if(k==a[i])

                     {

                    printf("\nElement %d is in the position %d",k,i+1);

                    f=2;

                    break;

                    } /* if */

          } /* for */

          if(f==1)

          printf("\nThe entered element is not in the array");

          printf("\nIf you want to continue y/n");

          ch=getch();

          c=ch;

} /* while */

getch();

} /* main */

OUTPUT

Enter the size of sorting 5

Enter the elements of the array 3 2 1 4 5

Enter the element to be searched 4

Element 4 is in the position 4

If you want to continue y/n

EXPLANATION : The above program reads the entered number of element through for loop. The program checks the specified element and position in the array according to the user entered number. Then the program prints the specified element and their position.



Computer Programming C Laboratory: String C Programs : Tag: C Programming : - C Program to find the specified element from the array using Linear searching


Computer Programming C Laboratory: String C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation