Untitled
unknown
plain_text
22 days ago
1.0 kB
1
Indexable
Never
#include <stdio.h> int main(void) { int a, ch=0, ne=0, i=0; FILE* inp = fopen("data.txt", "r"); if (inp == NULL) { printf("Error! No file!\n"); return 1; } while (fscanf(inp, "%d", &a) == 1) { i++; if(i%2==0){ //printf("Chislo %d\n", i); ch = ch+a; //printf("Chet = %d\n\n", b); } else { //printf("Chislo %d\n", i); ne = ne+a; //printf("Nechet = %d\n\n", c); } c } fclose(inp); if (i == 0){ printf("Error! No chisla!\n"); return 2; } //printf("Zakonch\n"); printf("Sum Nechet = %d\n", ne); printf("Sum Chet = %d\n\n", ch); if (ch==ne){ printf("Odinakovo\n"); } else{ if (ch>ne){ printf("Sum Chet Bolshe\n"); } else{ printf("Sum Nechet Bolshe\n"); } } return 0; }
Leave a Comment