User Tools

Site Tools


qna:lab-session:code2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

qna:lab-session:code2 [2024/04/24 15:34] (current)
xallos created
Line 1: Line 1:
 +<code c>#include <stdio.h>
  
 +int findInArray(
 +       double value,
 +       int N,
 +       double a[N]
 +) {
 +    for (int i = 0; i < N; ++i) {
 +        if (a[i] == value) {
 +            return i;
 +        }
 +    }
 +    return -1;
 +}
 +
 +int main() {
 +    double X[] = {1.2, 3.4, 5.6, 7.8};
 +    double someValue = 3.4;
 +    
 +    int index = findInArray(someValue, 4, X);
 +    
 +    printf("Found at position %d, value %lf\n", index, someValue);
 +
 +    return 0;
 +}</code>
qna/lab-session/code2.txt ยท Last modified: 2024/04/24 15:34 by xallos