EzicMan

z2

Sep 12th, 2019
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int getSum(const char* filename);
  4.  
  5. int getSum(const char* filename){
  6. FILE* input;
  7. int code, count = 0;
  8. long long a, sumch = 0, sumnch = 0;
  9. if((input = fopen(filename,"r")) == NULL){
  10. printf("Can't open file!");
  11. return -1;
  12. }
  13. while((code = fscanf(input,"%lld",&a)) == 1){
  14. if(a < 0){
  15. printf("Can't find modulus of negative numbers!\n");
  16. fclose(input);
  17. return -1;
  18. }
  19. if(a % 2 == 0){
  20. sumch += a;
  21. }else{
  22. sumnch += a;
  23. }
  24. count++;
  25. }
  26. if(code != EOF){
  27. printf("Can't read data from file!\n");
  28. fclose(input);
  29. return -1;
  30. }
  31. if(count == 0){
  32. printf("File is empty!\n");
  33. fclose(input);
  34. return -1;
  35. }
  36. fclose(input);
  37. if(sumch > sumnch){
  38. return 1;
  39. }else if(sumch == sumnch){
  40. return 2;
  41. }else{
  42. return 0;
  43. }
  44. }
  45.  
  46. int main(void){
  47. int code;
  48. code = getSum("test.txt");
  49. if(code == -1){
  50. return 1;
  51. }else if(code == 2){
  52. printf("equal\n");
  53. }else if(code == 1){
  54. printf("chetnye\n");
  55. }else if(code == 0){
  56. printf("nechetnye\n");
  57. }
  58. return 0;
  59. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×