Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- int N, V[5000], max = 0, R, sum = 0, nr;
- void Citire()
- {
- int i, element;
- FILE* f = fopen("in.txt", "r");
- if (f == NULL)
- {
- printf("Eroare la deschiderea fisierului f");
- exit(1);
- }
- fscanf(f, "%d ", &N);
- for (i = 0; i < N; i++)
- {
- fscanf(f, "%d", &element);
- V[i] = element;
- if (V[i] > max)
- max = V[i];
- sum = sum + V[i];
- }
- fclose(f);
- }
- void Afisare()
- {
- int i;
- FILE* f2 = fopen("out.txt", "w");
- if (f2 == NULL)
- {
- fprintf(f2, "Eroare la deschiderea fisierului f2");
- exit(1);
- }
- R = max;
- while (R <= sum / 2) {
- if (sum % R == 0) {
- max = 0;
- for (i = 0; i < N && max < R; i++) {
- max = max + V[i];
- if (max == R)
- max = 0;
- }
- if (i == N && max == 0) {
- fprintf(f2, "%d", R);
- return ;
- }
- }
- R++;
- }
- fprintf(f2, "%d", max);
- fclose(f2);
- }
- int main()
- {
- Citire();
- Afisare();
- return 0;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment