Pagini recente » Cod sursa (job #2573748) | Cod sursa (job #2355911) | Cod sursa (job #2536971) | Cod sursa (job #1015593) | Cod sursa (job #1342323)
#include <stdio.h>
#include <math.h>
int main()
{
const char *input_file = "cifra.in";
const char *out_file = "cifra.out";
FILE *in, *out;
int total, i, n;
unsigned long long int sum = 0ULL;
if ((in = fopen(input_file, "r")) == NULL) {
printf("Can't open the input file.\n");
return -1;
}
else if ((out = fopen(out_file, "w")) == NULL) {
printf("Can't open the output file.\n");
fclose(in);
return -1;
}
fscanf(in, "%i", &total);
while (total--) {
fscanf(in, "%i", &n);
sum = 0ULL;
for (i = 1; i <= n; ++i) {
sum += pow(i, i);
}
fprintf(out, "%llu\n", sum % 10);
}
fclose(out);
fclose(in);
return 0;
}