Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- FILE *file = fopen("eredmeny.txt", "w"); // ebbe a file-ba irjuk
- int osszeg = 0; // parosak osszege ez lesz
- printf("Kerem a szamokat:\n");
- for (int i=1; i<=10; i++) {
- int szam; // a kovetkezo szam
- printf("%d. ", i); // kiirjuk, hogy hanyadik szamot kerjuk
- scanf("%d", &szam);
- // file-ba irjuk az eredeti szamot (azt is, hogy hanyadik):
- fprintf(file, "%d. %d\n", i, szam);
- // ha paros, vagyis 2-vel osztas maradeka 0, akkor osszegezni kell:
- if (szam % 2 == 0)
- osszeg += szam;
- }
- printf("A parosak osszege: %d\n", osszeg);
- // A file-ba is kiirjuk:
- fprintf(file, "A parosak osszege: %d\n", osszeg);
- // Lezarjuk a file-t:
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment