Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int getSum(const char* filename);
- int getSum(const char* filename){
- FILE* input;
- int code, count = 0;
- long long a, sumch = 0, sumnch = 0;
- if((input = fopen(filename,"r")) == NULL){
- printf("Can't open file!");
- return -1;
- }
- while((code = fscanf(input,"%lld",&a)) == 1){
- if(a < 0){
- printf("Can't find modulus of negative numbers!\n");
- fclose(input);
- return -1;
- }
- if(a % 2 == 0){
- sumch += a;
- }else{
- sumnch += a;
- }
- count++;
- }
- if(code != EOF){
- printf("Can't read data from file!\n");
- fclose(input);
- return -1;
- }
- if(count == 0){
- printf("File is empty!\n");
- fclose(input);
- return -1;
- }
- fclose(input);
- if(sumch > sumnch){
- return 1;
- }else if(sumch == sumnch){
- return 2;
- }else{
- return 0;
- }
- }
- int main(void){
- int code;
- code = getSum("test.txt");
- if(code == -1){
- return 1;
- }else if(code == 2){
- printf("equal\n");
- }else if(code == 1){
- printf("chetnye\n");
- }else if(code == 0){
- printf("nechetnye\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement