BUT2/SCR/SCR2/TP03/ex5.c~

37 lines
626 B
C
Raw Permalink Normal View History

2023-10-12 16:39:49 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define SIZE 1000
int search0(const unsigned char * t,int start,int end)
{
int i;
for (i=start; i<end; i++){
if (t[i]=="0"){
return 1;
}
}
return 0;
}
int main(int argc , char * argv[])
{
unsigned char arr[SIZE];
int i;
srandom(time(NULL));
for (i = 0; i < SIZE; i++)
arr[i] = (unsigned char) (random() % 255) + 1;
printf("Enter a number between 0 and %d: ", SIZE);
scanf(" %d", &i);
if (i >= 0 && i < SIZE) arr[i] = 0;
if (search0(arr,0,SIZE-1))
printf("Found !\n");
else
printf("Not found !\n");
return EXIT_SUCCESS;
}