Full width home advertisement

HTML

Tech News

Ad

  1. #include<stdio.h>
  2.  
  3. int main(){
  4. int a[10],n=10,i,find;
  5.  
  6. for(i=0;i<n;i++){
  7. printf("Enter %d element ",i+1);
  8. scanf("%d",&a[i]);
  9. }
  10. printf("\n Enter element you want to find ");
  11. scanf("%d",&find);
  12.  
  13. for(i=0;i<n;i++){
  14. if(a[i]==find){
  15. printf("Element Found");
  16. break;
  17. }
  18. }
  19. if(a[i]!=find){
  20. printf("Element Not exist");
  21. }
  22.  
  23. return 0;
  24. }
  25.  

ALGORITHM

STEP 1:
    read a[n]
STEP 2:
    Repeat for i=1 to n step by one
        if(a[i]=x)
            then
                break Go to step 3
        end if
    end for

STEP 3:
    if i<=n
        then
             write "yes"
         else
            write "No"
    end if



Output

Linear search in c


No comments:

Post a Comment

Bottom Ad [Post Page]