Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Array first Occurence

#include  <stdio.h>
 
int rLookupAr(int *ar, int n, int target);
 
int main()
{
    int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
    printf("rLookupAr() with 0: %d
",  rLookupAr(a, 10, 0));
    printf("rLookupAr() with 3: %d
",  rLookupAr(a, 10, 3));
    printf("rLookupAr() with 9: %d
",  rLookupAr(a, 10, 9));
    printf("rLookupAr() with 20: %d
", rLookupAr(a, 10, 20));
    printf("rLookupAr() with -1: %d
", rLookupAr(a, 10, -1));
 
    return 0;
}
 
int rLookupAr(int *ar, int n, int target)
{
    if (n == 0) return -1;
    if (ar[0] == target) return 0;
 
    int _ret = rLookupAr(ar + 1, n - 1, target);
 
    if(_ret != -1) return ++_ret;
    else          return -1;
}
Comment

PREVIOUS NEXT
Code Example
Java :: day of week integer to name of day in java 
Java :: how do i get DefaultTableModel rows sum in column in java 
Java :: primefaces p:dataexporter encoding for pdf 
Java :: declare a variable java 
Java :: java skip foreach 
Java :: text with seek bar in android 
Java :: How to Register a Custom Auto-Configuration? 
Java ::         System.out.println("Welcome to GeeksforGeeks"); 
Java :: call to jdbc template each class not by super 
Java :: firemonkey android ini file read 
Java :: HashMap to Pojo 
Java :: Create dynamic tree view using JavaScript 
Java :: spigot item break 
Java :: get bimap by uri in android 
Java :: javafx get listview fxml id 
Java :: save ArrayList into Room Database android studio 
Java :: java window always on top 
Java :: Java Target annotations attributes 
Java :: strings in java are represented as 
Java :: what is a literal in java 
Java :: fix intellij resetting the java version everytime you add a dependency 
Java :: how to run javac xlint 
Java :: findbyname in jpa 
Java :: The larger and the smaller of the character “E” and the integer 71 java 
Java :: android java sqlite alter table 
Java :: struct in java 
Java :: jdk 17 not showing in update alternatives 
Java :: java try with multiple resources 
Java :: how to set edittext color in android 
Java :: unicode in java 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =