Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- #define size 10
- #define tolerance 0.1
- float getRandFloat(int min, int max) {
- // float f = (float)(rand() % (max - min + 1) + min);
- // return (float)rand()/(float)RAND_MAX/(float)max;
- float f = ((float)rand() / ((float)RAND_MAX/(float)(max-min)))+min;
- return f;
- }
- void main() {
- srand(time(0)); //tym sie nie przejmuj
- float tab[size];
- int min = 0, max = 10;
- for(int i = 0; i<size; i++) {
- tab[i] = getRandFloat(min, max);
- printf("%10.15f\n", tab[i]);
- }
- //tu sie konczy tworzenie tablicy po prostu i zaczyna wlasniwa czesc kodu
- float x;
- printf("Poodaj liuczbe z zakresu %d do %d\n", min, max);
- scanf("%f", &x);
- int index = -1, i = 0;
- do {
- if(fabs(x - tab[i]) < tolerance) {
- index = i;
- }
- i++;
- } while(i < size);
- if(index == -1) {
- printf("nie znaleziono");
- } else {
- printf("znalezniono na pozyhcj %d", index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment