admin@onlinelearningcenter.in (+91) 7 999 01 02 03

Find a number in an Array

Suraj Ghimire
13 Posts

Given an Array of 5 element, and a number num, Find out if the number is present or not in an array.

If it is present, return the index of it.

If it is not present, return -1.

 

arr[]={1,2,3,4,5}

num=4

Output: 3 (since 4 is present in index 3, as index starts from 0

 

arr[]={1,2,3,4,5}

num=8

Output: -1 (since element is not found)

 

 

 

 

 

Published By : Suraj Ghimire
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments

Jquery Comments Plugin