Skip to content

Commit

Permalink
Fix Añadido Ejercicio 8 B4
Browse files Browse the repository at this point in the history
  • Loading branch information
TeenBiscuits authored Nov 19, 2024
1 parent 232a469 commit f8574c6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/content/docs/prouno/boletines/B4-Boletin-4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,43 @@ El número 9 no aparece en el array.
<details>
<summary>Mostrar Solución</summary>
```c title="Ejercicio_08.c"
// SPDX-FileCopyrightText: 2024 Sprinter05
//
// SPDX-License-Identifier: GPL-3.0-only

// Libraries
#include <stdio.h>
#define N 10

int main(){
// Define variables and ask for parameters
int nums[N], guess, lGuess, uGuess;
printf("\nInput an array of 10 elements by pressing Enter after each element: ");
for(int i=0; i<10; i++){
scanf("%d", &nums[i]);
}
// Input guess
printf("\nWhat number do you want to find?: ");
scanf("%d", &guess);
// Lower bound
for(int i=0; i<N; i++){
if(nums[i] == guess){
lGuess = i;
break;
}
}
// Upper bound
for(int i=N; i>=0; i--){
if(nums[i] == guess){
uGuess = i;
break;
}
}
// Print solutions
printf("\nLower bound solution: %d", lGuess);
printf("\nUpper bound solution: %d", uGuess);
printf("\n");
}
```
</details>

Expand Down

0 comments on commit f8574c6

Please sign in to comment.