Pagini recente » Cod sursa (job #2556511) | Cod sursa (job #2231386) | Cod sursa (job #1042897) | Cod sursa (job #759690) | Cod sursa (job #2302347)
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX_SUM 2000000000
#define SUM(a,b) (a+b)
#define NUMBER_LIMIT INT_MAX-100
FILE* open_file(const char*);
short read_file(const FILE*, const int*, const int*);
void write_file(const FILE*, const int);
int main()
{
int a=0;
int b=0;
int c=0;
FILE *input = open_file("input.txt");
FILE *output = open_file("output.txt");
if(read_file(input, &a, &b))
c = SUM(a,b);
if(c<MAX_SUM)
write_file(output, c);
fclose(input);
fclose(output);
return 0;
}
FILE* open_file(const char* file_name){
FILE *f = NULL;
f = fopen(file_name, "r+");
return f;
}
short read_file(const FILE* input_file, const int *a, const int *b){
short r = 1;
fscanf(input_file, "%d", a);
fscanf(input_file, "%d", b);
if(*a > NUMBER_LIMIT || *b > NUMBER_LIMIT)
r=0;
return r;
}
void write_file(const FILE* output_file, const int sum){
fprintf(output_file, "%d", sum);
}