- Linear search without Functions from getting values from the user in c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[100],sk,c,n;
//get the size of the array from the user
printf("Enter the number of elements in the array\n");
scanf("%d",&n);
//Get the values for the array
printf("Enter %d Elements Please\n",n);
for(c=0;c<n;c++)
{
scanf("%d",&arr[c]);
}
//get the number to search from the array
printf("Please enter the Search Value\n");
scanf("%d",&sk);
for(c=0;c<n;c++){
if(arr[c]==sk){
printf("Search Value is allocated at the %d index",c);
break;
}
}
if(c==n){
printf("%d is not present in this array\n",sk);
}
return 0;
}
No comments:
Post a Comment