Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int i, x;
- int a, b, k;
- printf("a = ");
- scanf("%d",&a);
- printf("b = ");
- scanf("%d",&b);
- printf("k = ");
- scanf("%d",&k);
- x = rand()%(b + 1 - a) + a;
- printf("\n (x = %d)\n",x);
- int ok = 0;
- for (i=0; i<k; i++)
- {
- int guess;
- printf("Ghiciti numarul. ");
- scanf("%d",&guess);
- printf("\n");
- if (guess == x)
- {
- printf("Numar ghicit.");
- break;
- ok = 1;
- }
- }
- if (ok == 0)
- printf("\nNumarul nu a fost ghicit.");
- srand(time(NULL));
- return 0;
- }
- //////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int func(int m, int n, int (*f)(int))
- {
- int i, sum = 0;
- for (i=m; i<=n; i++)
- sum = sum + f(i);
- return sum;
- }
- int f1(int x)
- {
- return x*(x+1)/2;
- }
- int f2(int x)
- {
- return 3*x*x + 7;
- }
- int f3(int x)
- {
- if (x > 0)
- return 1;
- if (x < 0)
- return -1;
- return 0;
- }
- int main()
- {
- printf("%d",func(1,3,f2));
- return 0;
- }
- ///////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void *cautare(void *val, void *tablou, int nr_elemente, int dim_el)
- {
- int i, c = 0;
- char *pt = tablou;
- for (i=0; i<nr_elemente; i++)
- if (memcmp(val,pt + i*dim_el,dim_el) == 0)
- c++;
- return c;
- }
- int main()
- {
- int v[] = {1,2,2,4,5};
- int a = 2;
- printf("%d",cautare(&a,v,5,sizeof(int)));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement