Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdbool.h>
- int main()
- {
- FILE *f, *cit;
- int max = 0, N, i, K, j, v[100], n = 0,x,ok;
- f = fopen("ndk.out", "wt"); //Se creaza fisierul ndk.out
- cit = fopen("ndk.in", "a+t"); //Se creaza fisierul ndk.in
- if (cit == NULL)
- printf("Fisierul nu a fost creat!!\n");
- if (f == NULL)
- printf("Fisierul nu a fost creat!!\n"); //Se verifica daca cele 2 fisiere au fost create
- fscanf(cit, "%d", &N); //Se citeste numarul N
- fscanf(cit, "%d", &K); //Se citeste numarul K
- fscanf(cit, "%d", &v[1]);
- n = 1;
- for (i = 2; i <= N; i++)
- {
- fscanf(cit, "%d", &x);
- for (j = K-i; j <= K; j++)
- {
- ok = 1;
- if (j > 0)
- {
- if ((x + v[j]) % K != 0)
- ok = 0;
- }
- }
- if (ok == 1)
- v[++n] = x;
- if (n >= max)
- max = n;
- }
- fprintf(f, "Subsirul maxim este: %d\n", n);
- fclose(cit);
- fclose(f); // se inchid cele doua fisiere
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement